PHPackages                             nullref/yii2-cms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. nullref/yii2-cms

ActiveYii2-extension[Framework](/categories/framework)

nullref/yii2-cms
================

CMS for Yii2

v0.0.5(9y ago)93.2k5[7 issues](https://github.com/NullRefExcep/yii2-cms/issues)MITPHP

Since Nov 6Pushed 5y ago6 watchersCompare

[ Source](https://github.com/NullRefExcep/yii2-cms)[ Packagist](https://packagist.org/packages/nullref/yii2-cms)[ RSS](/packages/nullref-yii2-cms/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (7)Used By (0)

Content Management Module for Yii2
==================================

[](#content-management-module-for-yii2)

[![Latest Stable Version](https://camo.githubusercontent.com/f464733e51ba60c64e2a8dfc788c86399ab4c572c18a2efc1cbd9c369c4c0a76/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d636d732f762f737461626c65)](https://packagist.org/packages/nullref/yii2-cms) [![Total Downloads](https://camo.githubusercontent.com/56057f2231f2271e613e9e11a3ce6aeeed2ea5fa5c9bf4f7dcad79c825e35a37/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d636d732f646f776e6c6f616473)](https://packagist.org/packages/nullref/yii2-cms) [![Latest Unstable Version](https://camo.githubusercontent.com/38c845cfbf611e07271cf7e67dae7f948e0e09c6709101c9af958a2911a0c218/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d636d732f762f756e737461626c65)](https://packagist.org/packages/nullref/yii2-cms) [![License](https://camo.githubusercontent.com/30091987443cb5d0acdd263ce6fce83f1f43c05908b222eebe558e515f66fa71/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d636d732f6c6963656e7365)](https://packagist.org/packages/nullref/yii2-cms)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

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
-------

[](#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](https://github.com/MihailDev/yii2-ckeditor).

[User Guide](https://github.com/NullRefExcep/yii2-cms/blob/master/docs/UserGuide.md)
------------------------------------------------------------------------------------

[](#user-guide)

BlockManager
------------

[](#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
-----------

[](#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](https://github.com/NullRefExcep/yii2-cms/blob/master/src/components/LinkProvider.php) 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
--------------------------

[](#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
------------------

[](#single-block-usage)

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

```
use nullref\cms\components\Block;
?>
