RBAC Manager for Yii 2

Documentation

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require mdmsoft/yii2-admin "*"

for dev-master

php composer.phar require mdmsoft/yii2-admin "dev-master"

or add

"mdmsoft/yii2-admin": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply modify your application configuration as follows:

return [
    
'modules' => [
        
'admin' => [
            
'class' => 'mdm\admin\Module',
            
'layout' => 'left-menu'// avaliable value 'left-menu', 'right-menu' and 'top-menu'
            
'controllerMap' => [
                 
'assignment' => [
                    
'class' => 'mdm\admin\controllers\AssignmentController',
                    
'userClassName' => 'app\models\User',
                    
'idField' => 'user_id'
                
]
            ],
            
'menus' => [
                
'assignment' => [
                    
'label' => 'Grand Access' // change label
                
],
                
'route' => null// disable menu
            
],
        ]
        ...
    ],
    ...
    
'components' => [
        ....
        
'authManager' => [
            
'class' => 'yii\rbac\PhpManager'// or use 'yii\rbac\DbManager'
        
]
    ],
    
'as access' => [
        
'class' => 'mdm\admin\components\AccessControl',
        
'allowActions' => [
            
'admin/*'// add or remove allowed actions to this list
        
]
    ],
];

See Yii RBAC for more detail. You can then access Auth manager through the following URL:

http://localhost/path/to/index.php?r=admin
http://localhost/path/to/index.php?r=admin/route
http://localhost/path/to/index.php?r=admin/permission
http://localhost/path/to/index.php?r=admin/menu
http://localhost/path/to/index.php?r=admin/role
http://localhost/path/to/index.php?r=admin/assignment

To use menu manager (optional). Execute yii migration here: yii migrate --migrationPath=@mdm/admin/migrations

If You use database (class 'yii\rbac\DbManager') to save rbac data. Execute yii migration here: yii migrate --migrationPath=@yii/rbac/migrations

Class Reference

Class Description
mdm\admin\AdminAsset AdminAsset
mdm\admin\Module GUI manager for RBAC.
mdm\admin\components\AccessControl Access Control Filter (ACF) is a simple authorization method that is best used by applications that only need some simple access control.
mdm\admin\components\Configs Configs Used for configure some value. To set config you can use \yii\base\Application::$params
mdm\admin\components\DbManager DbManager represents an authorization manager that stores authorization information in database.
mdm\admin\components\MenuHelper MenuHelper used to generate menu depend of user role.
mdm\admin\components\RouteRule RouteRule Rule for check route with extra params.
mdm\admin\controllers\AssignmentController AssignmentController implements the CRUD actions for Assignment model.
mdm\admin\controllers\DefaultController DefaultController
mdm\admin\controllers\MenuController MenuController implements the CRUD actions for Menu model.
mdm\admin\controllers\PermissionController AuthItemController implements the CRUD actions for AuthItem model.
mdm\admin\controllers\RoleController AuthItemController implements the CRUD actions for AuthItem model.
mdm\admin\controllers\RouteController Description of RuleController
mdm\admin\controllers\RuleController Description of RuleController
mdm\admin\models\AuthItem This is the model class for table "tbl_auth_item".
mdm\admin\models\BizRule BizRule
mdm\admin\models\Menu This is the model class for table "menu".
mdm\admin\models\Route Route
mdm\admin\models\searchs\Assignment AssignmentSearch represents the model behind the search form about Assignment.
mdm\admin\models\searchs\AuthItem AuthItemSearch represents the model behind the search form about AuthItem.
mdm\admin\models\searchs\BizRule Description of BizRule
mdm\admin\models\searchs\Menu Menu represents the model behind the search form about mdm\admin\models\Menu.