Yii 问题中的访问规则
Access rule in Yii issue
当我登录时,它设置状态:
我的代码:
if (condition){
Yii::app()->user->setState('isSuperAdmin', true);
}else{
Yii::app()->user->setState('isSuperAdmin', false);
}
这是一个自定义控制器,名称为test,具有以下功能:
自定义控制器:
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'delete'),
'roles'=>array('Yii::app()->user->getState("isSuperAdmin")'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
Here it uses accessRules()
. I want to check if the isSuperAdmin
is set to
true, then I can access the controller test. Otherwise I don't have the role
to access.
我该怎么做?
您可以在访问规则中使用 expression:
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'delete'),
'expression'=>'Yii::app()->user->getState("isSuperAdmin")',
),
...
当我登录时,它设置状态:
我的代码:
if (condition){
Yii::app()->user->setState('isSuperAdmin', true);
}else{
Yii::app()->user->setState('isSuperAdmin', false);
}
这是一个自定义控制器,名称为test,具有以下功能:
自定义控制器:
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'delete'),
'roles'=>array('Yii::app()->user->getState("isSuperAdmin")'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
Here it uses
accessRules()
. I want to check if theisSuperAdmin
is set to true, then I can access the controller test. Otherwise I don't have the role to access.
我该怎么做?
您可以在访问规则中使用 expression:
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'delete'),
'expression'=>'Yii::app()->user->getState("isSuperAdmin")',
),
...