简体   繁体   中英

How to update RBAC database for Yii 2

I am using DbManager for RBAC. What is a good strategy for updating the RBAC database tables once they have been created? Is there a good extension that can be used to view the roles and rules and update them?

For RBAC with DbManager, (Yii2 Adevanced Template ) i use

  • In auth_permission table i use TYPE_PERMISSION for assign the permission (what i check for grant access) and TYPE_ROLE for create a application role.
  • auth_assignment table for assign the role to the user.
  • auth_item_child table for grouping the permission to a role.

For manage this ai have create a few views with gii, based on the normal RBAC table

I Hope this is useful for you

The native authManager is quite powerfull!

Here follows some examples.

Get the authManager instance

    $auth = \Yii::$app->authManager;

Create a Permission

    $permission = $auth->createPermission('/service-helper/*');
    $permission->description = 'Post';
    $auth->add($permission);

And add the Permission to a Role

    $userRole = $auth->getRole('editor');
    $auth->addChild($userRole, $permission);

See the Yii2 Authorization Guide that's quite exaustive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM