phpyii2rbacyii2-basic-appyii2-rbac

How to update assignment in auth_assignment table in Yii2 Rbac?


I am using RBAC in my yii2 basic application to assign module to users based on their roles.

I store role id and user_id in auth_assignment table.

Now if i change role of user during update. I have to change it also in auth_assignment table. Now I want to delete all entries of that user from auth assignment and add new entries in table.

The problem is that i cannot find any RBAC function to update auth_assignment table data or to delete auth assignment table data.

There is a function in Yii2 Documentation removeAllAssignments() but it truncates the whole table i only want to delete entries for perticular user.

Is there any function available for that?


Solution

  • Yes, there is.

    assign() assigns role to a user.
    revoke() revokes role from a user.
    revokeAll() revokes all roles from a user.

    To get the list of all roles assigned to a user you can use getRolesByUser().