A user has 3 roles.
- RoleOne
- RoleTwo
- RoleThree
After Login I want to activate one of his roles active mode and rest of roles inactive mode. Does Yii2 have any role switching technique? Or we have to make our own logic.
Here is how I am trying to achieve this...
$auth = new DbManager;
$auth->init();
//here I will get all roles of user
$roles = $auth->getRolesByUser(Yii::$app->user->identity->id);
Now after this how can set active role from $roles
variable. In between user can activate other roles also. I am here confused actually there is no yii2 functionality like switching roles any time after login.
Yii2 does not provide that extensive function that you're looking for. But try this https://github.com/webvimark/user-management module though. It is flexible and it has a helper that assigns roles as thus:
Read the documentation in the link above for more clarification on how it works