PHP code example of nullref / yii2-cms

1. Go to this page and download the library: Download nullref/yii2-cms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nullref / yii2-cms example snippets


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

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

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

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

/** 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);

use nullref\cms\components\Block;

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

/** 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',
    ],
],

php composer.phar