As in Yii 1.x, before performing the action of the controller, check: does the user have rights to perform this action and if he does not have to execute a certain code?

I try this in protected \ components \ Controller.php:

class Controller extends CController { protected function beforeAction($action) { if ( !Yii::app()->user->checkAccess($action->id) ) { // здесь мой код } return parent::beforeAction($action); } 

Unfortunately, the code does not work, because Yii::app()->user->checkAccess FALSE when it should be TRUE and vice versa.

What's wrong?

  • checkAccess takes in a sort of role name, not an identifier .... and the second parameter like the ID can be passed to yiiframework.com/doc/api/1.1/CWebUser#checkAccess-detail - Alexey Shimansky
  • not no, the first parameter is also written there: "the need for access check." - this is definitely not a role, but the name of the operation. Probably the action of the controller cannot be transferred there, only the name of the operation defined through the business rule. - Enshtein
  • Well, yes, I meant this and that the operation)) operations that you yourself define somewhere can this help yiiframework.ru/doc/guide/ru/topics.auth - Alexey Shimansky
  • naturally, I was looking at the help section) I just had a look at checkAccess, now I’m not sure what to do or how to be. And the task is banal ... - Enshtein
  • the only option is probably to make a fuss with accessRules () and for each one there create $ auth-> createOperation () then use Yii :: app () -> user-> checkAccess - Enshtein

0