yii-admin組件來管理角色和權限

  1. 安裝yii-admin組件
    composer require mdmsoft/yii2-admin "~2.0"

     

  2. 配置 backend\config\main.php
    return [
        //......
        'modules' => [
            'admin' => [        
                'class' => 'mdm\admin\Module',   
            ],
            //......
        ],
        'aliases' => [    
            '@mdm/admin' => '@vendor/mdmsoft/yii2-admin',
        ],
        'components' => [
            //......
            'authManager' => [        
                'class' => 'yii\rbac\DbManager',
                'defaultRoles' => ['guest'],    
            ],
            //......
        ],
        'as access' => [
            'class' => 'mdm\admin\components\AccessControl',
            'allowActions' => [
                //這裏是容許訪問的action,不授權限控制,先用'*'設置成所有開放
                '*'
            ]
        ],
        //......
    ];

     

  3. 經過訪問如下頁面進行可視化操做來管理配置路由、角色、權限
    /index.php?r=admin
    /index.php?r=admin/route
    /index.php?r=admin/permission
    /index.php?r=admin/role
    /index.php?r=admin/assignment
相關文章
相關標籤/搜索