I am using Yii2 basic.
I have Employee table and I have assigned Employee model to user application component as follows in config file:
'user' => [
'identityClass' => 'app\models\Employee',
'enableSession' => true,
],
I have also created permissions, roles and assigned roles to employees using RBAC.
1. Now when employee whose role is admin logs in, he can see foll menus on sidebar of Admin LTE:
- Masters
- Employee
- Employee Training
- SHGProfile
- Survey
When employee whose role is fieldofficer logs in, he also sees above menus on sidebar. Fieldofficer should only see foll menus:
- My Profile
- SHGProfile
How to change the menus on sidebar of Admin LTE as per roles of the employees?
2. Employee should be able to log in to the system only if role is assigned to employee. How to accomplish this?
I am kind of new to Yii 2, did something like this, last week. Hope it helps.
You can use Rbac to accomplish the task you want to. To know more about RBAC: https://en.wikipedia.org/wiki/Role-based_access_control
There is a Yii 2 plugin to implement RBAC in your system. https://github.com/dektrium/yii2-rbac
You can assign roles to users. And give permissions to those roles, basically it is a parent child kin of relationship.
Whenever you create a new user assign permission to it as follows:
Assign permission to a role:
Check if a user has permission or not using:
Yii::$app->user->can('permCheckAdmin');
Hope it helps