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:

  1. masters
  2. employee
  3. employee training
  4. shgprofile
  5. survey

when employee role fieldofficer logs in, sees above menus on sidebar. fieldofficer should see foll menus:

  1. my profile
  2. 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 id 
  • assign 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

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -