An error is reported when yii2 authenticates the permission on the controller.

Source: Internet
Author: User
The code in the controller is publicfunctionbeforeAction ($ action) {code ...}} the prompt "no operation permission" is displayed on the page. the corresponding $ contro... is added to the database... rbac permission can be verified normally, but an exception is thrown during Controller authentication.
The code in the controller is like this.

Public function beforeAction ($ action ){

$ Controller = Yii ::$ app-> controller-> id; // Obtain the controller $ action = Yii ::$ app-> controller-> action-> id; // Obtain the method if (Yii: $ app-> user-> can ($ controller. '_'. $ action) {return true;} else {throw new \ yii \ web \ UnauthorizedHttpException ('you do not have operation authorization ');}

}
The prompt "no operation permission" is displayed on the page. the corresponding $ controller is added to the database. '_'. $ action data ...........

Reply content:

Rbac permission can be verified normally, but an exception is thrown during Controller authentication.
The code in the controller is like this.

Public function beforeAction ($ action ){

$ Controller = Yii ::$ app-> controller-> id; // Obtain the controller $ action = Yii ::$ app-> controller-> action-> id; // Obtain the method if (Yii: $ app-> user-> can ($ controller. '_'. $ action) {return true;} else {throw new \ yii \ web \ UnauthorizedHttpException ('you do not have operation authorization ');}

}
The prompt "no operation permission" is displayed on the page. the corresponding $ controller is added to the database. '_'. $ action data ...........

Write real addresses in the data, for example:
'/'. $ Controller. '/'. $ action

Output$controller.'_'.$actionThis variable is used by myself under the parent class,
Yii: $ app-> controller-> id and Yii: $ app-> controller-> action-> id are null.

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.