I'm using yii2 role based access control (RBAC) system. I defined roles and permissions, defined rules, assigned roles to users. Everything works fine.
but i want to update assigned roles to users. For example:
Yii::$app->authManager->assign('admin', '11');
Here i did user id 11 admin. Now i want to update and change. I want to make this user manager.
When i try:
Yii::$app->authManager->assign('manager', '11');
This user have admin + manager. I just want to update this user role admin to manager.
How can i do this?
first you revoke() or revokeAll() user role:
Remove current role 'admin':
$manager = Yii::$app->authManager;
$item = $manager->getRole('admin');
$item = $item ? : $manager->getPermission('admin');
$manager->revoke($item,'11');
and again update new role to user:
$authorRole = $manager->getRole('manager');
$manager->assign($authorRole, 11);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With