定制 nullref/yii2-cms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nullref/yii2-cms

Composer 安装命令:

composer require nullref/yii2-cms

包简介

CMS for Yii2

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist nullref/yii2-cms "*"

or add

"nullref/yii2-cms": "*"

to the require section of your composer.json file.

Run command php yii module/install nullref/yii2-cms to install this module. It will be added to your application config (@app/config/installed_modules.php)

Concept

This module allows you to build dynamic pages which consist of blocks (widget with config). You can create custom widgets and register it in BlockManager.

Also you can create pages with html content by WYSIWYG CKEditor.

User Guide

BlockManager

This component contains information about available blocks. You can override it:

    'cms' => [
        'class' => 'nullref\\cms\\Module',
        'components' => [
            'blockManager' => 'app\components\BlockManager',
        ]
    ],

and add in your class own blocks:

class BlockManager extends BaseBlockManager
{
    public function getList()
    {
        return array_merge([
            'smile' => 'app\blocks\smile', //namespace of block files
        ], parent::getList());
    }
}

To register block at runtime:

    Block::getManager()->register('smile','app\blocks\smile');
    //or
    Yii::$app->getModule($moduleId)->get('blockManager')->register('smile','app\blocks\smile');

LinkManager

This component is used for unified access to links of different resources (e.g. page or categories). Manager can generate link to resource by it type and id. If you want to add own type of links you need to add link provider to this manager by definition container (DI). For example:

Yii::$container->set(LinkManager::className(), [
    'class' => LinkManager::className(),
    'providers' => [
        'page' => [
            'class' => 'app\modules\cms\components\PageLinkProvider',
        ],
],]);

Each link provider must to impelement LinkProvider interface.

As result you can use this manager to generate link in your widgets or other application parts. E.g:

/** in some component constructor define additional parameter and set it in class property **/
public function __construct(LinkManager $linkManager, $config = [])
{
    $this->linkManager = $linkManager;
    parent::__construct($config);
}
/** generate link **/
echo $this->linkManager->createUrl('page', $id);

Block structure convention

A valid block is represented by a folder with two classes:

  • Block - define data block to use
  • Widget - run with data when this block use on page

In most cases form file will also be in this folder

When you add own block you have to set unique id and namespace of block files folder.

Single block usage

You can use cms blocks on you own views, to call by id:

use nullref\cms\components\Block;
?>
<div class="site-index">
    <?= Block::getBlock('hello')->run() ?>
    or
    <?= Block::getBlock('hello2') //block has override method __toString() ?>
</div>

Pages

This module allows to create pages with custom content and set custom url for it. By default all pages are available by route /pages/<route>, but you can override it by config:

/** module config **/
'cms' => [
    'class' => 'nullref\cms\Module',
    'urlPrefix' => '', //make empty prefix
],

By default you can set meta tags for each page. Default tags are:

  • title
  • description
  • keywords
  • robots

You can override method getMetaTypesList in Page model class (see below) to extend it.

Overriding

  • Models and ActiveQueries:
/** module config **/
'cms' => [
    'classMap' => [
        'Block' => 'app\models\cms\Block',
        'BlockQuery' => 'app\models\cms\BlockQuery',
        'Page' => 'app\models\cms\Page',
        'PageHasBlock' => 'app\models\cms\PageHasBlock',
        'PageQuery' => 'app\models\cms\PageQuery',
    ],
],
[
 /** App config **/
 'components' => [
  'i18n' => [
      'translations' => [
          '*' => ['class' => 'yii\i18n\PhpMessageSource'],
          'cms' => ['class' => 'nullref\core\components\i18n\PhpMessageSource'],
      ],
  ],
 ]
]
/** App config **/
'components' => [
    'view' => [
        'theme' => [
            'pathMap' => [
                '@nullref/cms/views' => '@app/views/cms'
            ],
        ],
    ],
],
/** module config **/
'cms' => [
    'class' => 'nullref\cms\Module',
    'controllerNamespace' => 'app\modules\cms\controllers',
    'controllerMap' => [
        // declares "page" controller using a class name
        'page' => 'app\controllers\PageController',
    ],
],

Admin Panel

You can use this module with Yii2 Admin module.

nullref/yii2-cms 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 6
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-28