dmstr/yii2-pages-module 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dmstr/yii2-pages-module

Composer 安装命令:

composer require dmstr/yii2-pages-module

包简介

Application sitemap and navigation manager module for Yii 2.0 Framework

README 文档

README

Latest Stable Version Total Downloads License

Application sitemap and navigation manager module for Yii 2.0 Framework

  • ⚠️ Breaking changes in 0.14.0 and 0.18.0
  • ⚠️ copy pages is removed in versions > 2.5.0

data structure and public properties are updated and query menu items from now on via domain_id

Requirements

  • URL manager from codemix/yii2-localeurls configured in application
  • role based access control; auth_items for every module_controller_action

Installation

The preferred way to install this extension is through composer.

Either run

composer require dmstr/yii2-pages-module "*"

or add

"dmstr/yii2-pages-module": "*"

to the require section of your composer.json file.

Setup

Run migrations

./yii migrate \
    --disableLookup=1 \
    --migrationPath=@vendor/dmstr/yii2-pages-module/migrations

Configuration

Enable module in application configuration

// module configuration
'pages' => [
	'class' => 'dmstr\modules\pages\Module',
	'layout' => '@admin-views/layouts/main',
	'roles' => ['Admin', 'Editor'],
	'defaultPageLayout' => '@app/modules/frontend/layouts/main',
	'availableRoutes' => [
		'site/index' => 'Index Route',
	],
	'availableViews' => [
		'@app/views/site/index.php' => 'Index View',
	],
],


// if used want a url suffix, e.g. '.html', add Url rules for that
'urlManager' => [
	...
	'rules' => [
		'<pagePath:[a-zA-Z0-9_\-\./\+]*>/<pageSlug:[a-zA-Z0-9_\-\.]*>-<pageId:[0-9]*>.html' => 'pages/default/page',
		'<pageSlug:[a-zA-Z0-9_\-\.]*>-<pageId:[0-9]*>.html' => 'pages/default/page',
	],
	...
],

// register frontend asset for hiding pages via CookieButton
'on '. \yii\web\Application::EVENT_BEFORE_ACTION => function () {
    \dmstr\modules\pages\assets\PagesFrontendAsset::register(Yii::$app->controller->view);
},

Use settings module to configure additional controllers

  • Add one controller route per line to section pages, key availableRoutes

Settings

  • pages.availableRoutes - routes per access_domain (for non-admin users)
  • pages.availableViews - views per access_domain (for non-admin users)
  • pages.availableGlobalRoutes - global routes (for admin users)
  • pages.availableGlobalViews - global views(for admin users)

Usage

Navbar (eg. layouts/main)

find a root node / leave node

by domain_id i.e. root

$menuItems = \dmstr\modules\pages\models\Tree::getMenuItems('root');

use for example with bootstrap Navbar

    echo yii\bootstrap\Nav::widget(
        [
            'options'         => ['class' => 'navbar-nav navbar-right'],
            'activateItems'   => false,
            'encodeLabels'    => false,
            'activateParents' => true,
            'items'           => Tree::getMenuItems('root'),
        ]
    );

Backend

  • visit /pages to create a root-node for your current application language.
  • click the tree icon
  • enter name identifier (no spaces and special chars) as Domain ID and Menu name and save
  • create child node
  • assign name, title, language and route/view
  • save

Now you should be able to see the page in your Nav widget in the frontend of your application.

Traits

We use the \dmstr\activeRecordPermissions\ActiveRecordAccessTrait to have a check access behavior on active record level

  • Owner Access
  • Read Access
  • Update Access
  • Delete Access

Anchors

available since 0.12.0-beta1

👷 A workaround for creating anchor links is to define a route, like /en/mysite-2 in the settings module. On a node you can attach an anchor by using Advanced URL settings, with {'#':'myanchor'}.

It is recommended to create a new entry in Tree mode.

i18n - sibling pages

Find sibling page in target language

/**
 * Find the sibling page in target language if exists
 *
 * @param string $targetLanguage
 * @param integer $sourceId
 * @param string $route
 *
 * @return Tree|null
 * @throws \yii\console\Exception
 */
public function sibling($targetLanguage, $sourceId = null, $route = self::DEFAULT_PAGE_ROUTE);


Example 1:
---

// page id 12 is a node in language 'en'
$sourcePage = Tree::findOne(12);

// returns corresponding page object in language 'de' or null if not exists
$targetPage = $sourcePage->sibling('de');


Example 2:
---

// find by params
$targetPage = (new Tree())->sibling('de', 12, '/pages/default/page')

Testing

Requirements:

  • docker >=1.9.1
  • docker-compose >= 1.6.2

Codeception is run via "Potemkin"-Phundament.

cd tests

Start test stack

make all

Run tests

make run-tests

Changelog

2.5.10

  • Removed localized root node message
  • Updated kartik-v/yii2-tree-manager requirement to ^1.1.2
  • Update Tree model to support new child_allowed attribute (since kartik-v/yii2-tree-manager 1.0.9)
  • Improved permission check for page nodes so allowed child nodes in not allowed parents do not show up

dmstr logo Built by dmstr

dmstr/yii2-pages-module 适用场景与选型建议

dmstr/yii2-pages-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79.9k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2015 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Sitemap」 「extension」 「navigation」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dmstr/yii2-pages-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dmstr/yii2-pages-module 我们能提供哪些服务?
定制开发 / 二次开发

基于 dmstr/yii2-pages-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 79.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 31
  • 点击次数: 11
  • 依赖项目数: 3
  • 推荐数: 1

GitHub 信息

  • Stars: 31
  • Watchers: 9
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-04-21