pavlinter/yii2-adm

Yii2: Adm CMS

Installs: 444

Dependents: 2

Suggesters: 0

Security: 0

Stars: 8

Watchers: 6

Forks: 7

Open Issues: 0

Type:yii2-extension

v2.0.7 2017-12-10 08:39 UTC

README

Screen Shot

Установка

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

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

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

pavlinter/yii2-dot-translation
pavlinter/yii2-url-manager
pavlinter/yii2-buttons
mihaildev/yii2-ckeditor
mihaildev/yii2-elfinder
kartik-v/yii2-grid
kartik-v/yii2-detail-view
kartik-v/yii2-widgets
kartik-v/yii2-checkbox-x
kartik-v/yii2-icons

Настройка

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

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

Генерируешь модуль через gii или создаём сами ...

'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;
}
  • Частично закрыть доступ к модулю
//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'],
                ],
            ],
        ],
    ];
}
  • Если публичный модуль, то нужно создавать manager класов.
    Пример
    Manager