Yii2rbac needs to verify each time a method is used. Is there any permission? How can I configure it if it is configured?

Source: Internet
Author: User
Yii2rbac needs to verify whether the user has the permission to control the controller and Action each time a method is used? How can I configure it if it is configured? Yii2 rbac needs to verify whether the user has the permission to control the controller and Action each time a method is used? How can I configure it if it is configured?

Reply content:

Yii2 rbac needs to verify whether the user has the permission to control the controller and Action each time a method is used? How can I configure it if it is configured?

Yii \ filters \ AccessRule: matchCalllback. Pay attention to the passed parameters $ rule, $ action

[    'actions' => ['special-callback'],    'allow' => true,    'matchCallback' => function ($rule, $action) {        # write arbitrary access check logic        # permission = (rule [xxoo] action)        # return user->can(permission);    }]

Or use the following method, see yii2-admin

return [    'components' => [        'authManager' => [            'class' => 'yii\rbac\PhpManager', // or use 'yii\rbac\DbManager'        ]    ],    'as access' => [        'class' => 'mdm\admin\components\AccessControl',    ],];

AccessControl supports role configuration

For example:

[    'actions' => ['edit'],    'allow' => true,    'roles' => ['@', 'author'],],

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.