Try changing 'users'=>array('admin') to 'roles'=>array('admin')
Yii simple rbac - checkAccess is not executed
题
I'm new to Yii. I used this tutorial: http://www.yiiframework.com/wiki/328/simple-rbac/ to make admin role working. My accessRules function in controller looks like this:
public function accessRules() {
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions' => array('index', 'view', 'create'),
'users' => array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions' => array('update'),
'users' => array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions' => array('delete', 'admin'),
'users' => array('admin'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
If I understood - it should execute checkAccess function from WebUser class when I try to view admin or delete action. My checkAccess function looks like this:
public function checkAccess($operation,$params=array(),$allowCaching=true) {
die("it works!");
if (empty($this->id)) {
// Not identified => no rights
return false;
}
$admin = $this->getState("admin");
return ($operation === 'admin' && $admin == ROLE_ADMIN || $operation !== 'admin');
}
So it should view "it works!" but I get
Error 403
You are not authorized to perform this action.
What did I do wrong?
解决方案
不隶属于 StackOverflow