adminlte - How to change menus on sidebar of Admin LTE as per roles in yii2? -
i using yii2 basic.
i have employee table , have assigned employee model user application component follows in config file:
'user' => [ 'identityclass' => 'app\models\employee', 'enablesession' => true, ], i have created permissions, roles , assigned roles employees using rbac.
1. when employee role admin logs in, can see foll menus on sidebar of admin lte:
- masters
- employee
- employee training
- shgprofile
- survey
when employee role fieldofficer logs in, sees above menus on sidebar. fieldofficer should see foll menus:
- my profile
- shgprofile
how change menus on sidebar of admin lte per roles of employees?
2. employee should able log in system if role assigned employee. how accomplish this?
i kind of new yii 2, did this, last week. hope helps.
you can use rbac accomplish task want to. know more rbac: https://en.wikipedia.org/wiki/role-based_access_control
there yii 2 plugin implement rbac in system. https://github.com/dektrium/yii2-rbac
you can assign roles users. , give permissions roles, parent child kin of relationship.
whenever create new user assign permission follows:
$auth = yii::$app->authmanager; $admin = $auth->getrole('admin'); $auth->assign($admin, 1); // second parameter user idassign permission role:
$auth = yii::$app->authmanager; $admin = $auth->getrole('admin'); $permcheckadmin = $auth->createpermission('permcheckadmin'); $permcheckadmin->description = 'check if admin'; $auth->add($permcheckadmin); $auth->addchild($admin, $permcheckadmin);check if user has permission or not using:
yii::$app->user->can('permcheckadmin');
- you can assign permissions admin , employee , use action according permission.
hope helps
Comments
Post a Comment