Yii i want to get all actions that a user is authorized to perform

有些话、适合烂在心里 提交于 2019-12-24 16:06:48

问题


how can i get back the actions i defined in my accessrules function

public function accessRules(){
    return array(
                 'allow',
                 'actions'=>array('create','update' ...),
                  ....
                 )
}

i need them for dislay reason something like if(in_array('create',$actions)) echo CHtml::link('link to create form') or may be something like if(user->isAutorizedToPerfoem('create')).

thanx in advance


回答1:


I think this is not possible when you use the accessControl filter. The authorization data is in this case saved directly in the controller, so you technically have to be in the controller to see the accessRules(). And you cannot check access manually, as far as I know. The filter does the work there. You can see your acces rules by calling $this->accessRules, but well you have to be in the controller.

You probably have to use RBAC and save your access rules externally. Read here for more information: Yii Documentation - role based access control

There is also a quite capable Yii extension called Rights, which provides a backend for RBAC.

This might seem like overkill for the moment, but RBAC is unmatched in flexibility. If you use it, you can check access like Yii::app->user->checkAccess('post.create'), and many other things.



来源:https://stackoverflow.com/questions/10566571/yii-i-want-to-get-all-actions-that-a-user-is-authorized-to-perform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!