2017 © Pedro Peláez
 

yii2-extension yii2-adm

Yii2: Adm CMS

image

pavlinter/yii2-adm

Yii2: Adm CMS

  • Sunday, December 10, 2017
  • by pavlinter
  • Repository
  • 5 Watchers
  • 9 Stars
  • 404 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 27 Versions
  • 0 % Grown

The README.md

Screen Shot, (*1)

Установка

Удобнее всего установить это расширение через composer., (*2)

"pavlinter/yii2-adm": "dev-master",

Список включающих пакетов

pavlinter/yii2-dot-translationbr/ pavlinter/yii2-url-managerbr/ pavlinter/yii2-buttonsbr/ mihaildev/yii2-ckeditorbr/ mihaildev/yii2-elfinderbr/ kartik-v/yii2-gridbr/ kartik-v/yii2-detail-viewbr/ kartik-v/yii2-widgetsbr/ kartik-v/yii2-checkbox-xbr/ kartik-v/yii2-iconsbr/, (*3)

Настройка

//console.php
'components' => [
    ...
    'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
    ...
],
//main.php
'bootstrap' => [
    'urlManager',
    'i18n',
],
'modules' => [
    'adm' => [
        'class' => 'pavlinter\adm\Adm',
        'modules' => [

        ],
        /*
        'components' => [
            'manager' => [
                'loginFormClass' => 'pavlinter\adm\models\LoginForm',
                'userClass' => 'pavlinter\adm\models\User',
                'userSearchClass' => 'pavlinter\adm\models\UserSearch',
                'authItemClass' => 'pavlinter\adm\models\AuthItem',
                'authItemSearchClass' => 'pavlinter\adm\models\AuthItemSearch',
                'authRuleClass' => 'pavlinter\adm\models\AuthRule',
                'authRuleSearchClass' => 'pavlinter\adm\models\AuthRuleSearch',
                'authItemChildClass' => 'pavlinter\adm\models\AuthItemChild',
                'authItemChildSearchClass' => 'pavlinter\adm\models\AuthItemChildSearch',
                'authAssignmentClass' => 'pavlinter\adm\models\AuthAssignment',
                'authAssignmentSearchClass' => 'pavlinter\adm\models\AuthAssignmentSearch',
                'languageClass' => 'pavlinter\adm\models\Language',
                'languageSearchClass' => 'pavlinter\adm\models\LanguageSearch',
                'sourceMessageClass' => 'pavlinter\adm\models\SourceMessage',
                'sourceMessageSearchClass' => 'pavlinter\adm\models\SourceMessageSearch',
                'messageClass' => 'pavlinter\adm\models\Message',
            ],
        ],
        */
    ],
    'gridview'=> [
        'class'=>'\kartik\grid\Module',
    ],
    'gii' => [
        'class'      => 'yii\gii\Module',
        'generators' => [
            'model'   => [
                'class'     => '\pavlinter\adm\gii\generators\model\Generator',
            ],
            'crud'   => [
                'class'     => '\pavlinter\adm\gii\generators\crud\Generator',
            ],
            'module'   => [
                'class'     => '\pavlinter\adm\gii\generators\module\Generator',
            ],
        ]
    ],
],
'components' => [
    'user' => [
        'identityClass' => 'pavlinter\adm\models\User',
        'enableAutoLogin' => true,
    ],
    'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
    'urlManager' => [
        'class'=>'\pavlinter\urlmanager\UrlManager', //https://github.com/pavlinter/yii2-url-manager
        'enableLang' => true,
        'langBegin' => ['ru','en'],
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'onlyFriendlyParams' => false,
        'ruleConfig' => [
            'class' => '\pavlinter\urlmanager\UrlRule',
        ],
        'rules' => []
    ],
    'i18n' => [
        'class'=>'pavlinter\translation\I18N', //https://github.com/pavlinter/yii2-dot-translation
        'access' => function () {
            return Yii::$app->getUser()->can('Adm-Transl');
        },
        'dialog' => 'jq',
        'router' => '/adm/source-message/dot-translation',
        'translations' => [
            'app*' => [
                'class' => 'pavlinter\translation\DbMessageSource',
                'forceTranslation' => true,
                'autoInsert' => true,
                'dotMode' => true,
            ],
        ],
    ],
],

Запустить миграцию

yii migrate --migrationPath=@vendor/pavlinter/yii2-adm/adm/migrations

Вход в adm

http://domain.com/adm

Доступ

username: adm
password: 123456

Дополнительный модуль

yii2-adm-pages, (*4)

Как дополнить adm?

Генерируешь модуль через gii или создаём сами ..., (*5)

'modules' => [
    ...
    'adm' => [
        ...
        'modules' => [
            'my_module' // вызываем метод pavlinter\my_module\Module::loading когда adm layout
        ],
        ...
    ],
    'my_module' => [
        'class' => 'pavlinter\my_module\Module',
    ],
    ...
],
  • Добавить в adm в левое меню свой модуль
//app\my_module\Module

class Module extends \yii\base\Module implements \pavlinter\adm\AdmBootstrapInterface
{
    ...
    public function loading($adm)
    {
        if ($adm->user->can('AdmRoot')) {
            $adm->params['left-menu']['my_module'] = [
                'label' => '<i class="fa fa-file-text"></i><span>' . $adm::t('menu', 'My module') . '</span>',
                'url' => ['/my_module/default/index']
            ];
        }
    }
    ...
}
  • Полностью закрыть доступ к модулю.
//app\my_module\Module
public function beforeAction($action)
{
    $adm = Adm::register();
    if (!parent::beforeAction($action) || !$adm->user->can('AdmRoot')) {
        return false;
    }
    return true;
}
  • Частично закрыть доступ к модулюbr/
//app\my_module\Module
public function beforeAction($action)
{
    if ($action->controller->id !== 'default') {
        $adm = Adm::register();
    }
    return parent::beforeAction($action);
}
//app\my_module\controllers\MyController
public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['MyRole'],
                ],
            ],
        ],
    ];
}

The Versions