PHPackages                             webkadabra/yii2-cms-module - 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. webkadabra/yii2-cms-module

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

webkadabra/yii2-cms-module
==========================

Yii2 CMS &amp; Router Module

2311PHP

Since Sep 11Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Webkadabra/yii2-cms-module)[ Packagist](https://packagist.org/packages/webkadabra/yii2-cms-module)[ RSS](/packages/webkadabra-yii2-cms-module/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-cms-module
===============

[](#yii2-cms-module)

A CMS &amp; routing module for Yii 2 applications.

Features:

- content version history &amp; sandbox mode
- multilingual support
- handles routing on top of built-in `urlManager`
- manage URL redirects
- sitemap support

Installation via Composer
-------------------------

[](#installation-via-composer)

You can install package with a command:

> composer require webkadabra/yii2-cms-module

Setup
-----

[](#setup)

**Note**\*: even though this module will run on most of MySQL versions, automated migrations require MySql &gt;= 5.6.

### Configuration

[](#configuration)

Add `cms` component to your main application configuration (e.g. `config/main.php` or `frontend/config/main.php`, depending on your application structure):

```
// ...
'components' => [
        // ...
        'cms' =>[
            'class' => 'webkadabra\yii\modules\cms\components\CmsRouter',
        ],
        // ...
],
// ...

```

Add `cms` component to `bootstrap` property at your main application config (usually, the same file as in previous step):

```
// ...
    'bootstrap' => ['log',  'cms', /* ... other conponents ... */],
],
// ...

```

Add `cms-web` module to your main (web) application:

```
// ...
'modules' => [
        // ...
        'cms-web' => 'webkadabra\yii\modules\cms\Module',
        // ...
],
// ...

```

Add `cms` module to your admin or backend application (it can be the same application config):

```
// ...
'modules' => [
        // ...
        'cms' => [
            'class' => 'webkadabra\yii\modules\cms\AdminModule',
            'availableControllerRoutes' => [
                'site' => [
                    'label' => 'Global',
                    'actions' => [
                        'index' => 'Home page',
                        'contact' => 'Contact page',
                        'page' => [
                            'label' => 'Static page',
                            'params' => [
                                ['view' => 'File name'],
                            ],
                            #'params'=>['id', 'dummy'], // For multiple params
                        ],
                    ],
                ],
                'rss'=>[
                    'label' => 'RSS feeds controller',
                    'actions'=>[
                        'view'=>[
                            'label'=>'Display feed',
                            'params'=>['id'], // Required or available action params
                        ],
                    ],
                    'store' => [
                        'label' => 'Store',
                        'actions' => [
                            'index' => 'Store front page',
                            'good' => [
                                'label' => 'Offer page',
                                'params' => [
                                    ['alias' => 'Offer code (alias or SKU)'],
                                ],
                            ],
                            'listCategory' => [
                                'label' => 'Offers in a category',
                                'params' => [
                                    ['alias' => 'Category code (alias)'],
                                ],
                            ],
                            'promotion' => [
                                'label' => 'Promo page',
                                'params' => [
                                    ['promoid' => 'Promotion ID'],
                                    ['promoName' => 'Promotion name'],
                                ],
                            ],
                        ],
                    ],
                ]
            ],
        ],
        // ...
],
// ...

```

Make sure you have create folder where module will look for template files. By default, it's `@app/views/cms-templates`

(optional) Add module migrations folder to your console application config file (or main config file, if you're not using advanced application structure):

```
// ...
'controllerMap' => [
    'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => [
                '@app/migrations',
                'vendor/webkadabra/yii2-cms-module/migrations',
            ],
        ],
],
// ...

```

... and then run `php yii migrate` command. If you choose not to add module's migrations path to your config, you can setup database by running migrations directly:

> $ php yii migrate --migrationPath=@vendor/webkadabra/yii2-cms-module/migrations

NOTICE: you will have to run this command every time there is a change in modules' migrations.

Finally, for the best admin experience, make sure your admin layout files do output blocks `actions`, `links` and `footer`. You can do it by adding this code to your layouts:

```
    // ...
    if (isset($this->blocks['actions'])) {
        echo $this->blocks['actions'];
    }
    if (isset($this->blocks['links'])) {
        echo $this->blocks['links'];
    }
    if (isset($this->blocks['footer'])) {
        echo $this->blocks['footer'];
    }
    // ...
```

Multilingual websites
---------------------

[](#multilingual-websites)

This module will automatically start working in multilingual mode with `omgdef\multilingual` extension

Usage
-----

[](#usage)

### Template files

[](#template-files)

Each PHP template must have a block of comments at the beginning of a file for it to be used in CMS module. Example of such code block:

```
