我遇到访问控制问题。我有规则:
array('deny',
'actions'=>array('index'),
'expression'=>'Yii::app()->user->isRegistered()',
'deniedCallback' => array(
$this->render('//site/info',array(
'message'=>'You must activate your account.'
)
),Yii::app()->end()),
),
功能
public function isRegistered()
{
return (Yii::app()->user->isGuest) ? FALSE : $this->level == 1;
}
如果我以管理员身份登录并且我有3级,则isRegistered()返回false,但deniedCalback会运行。
如果只在expression为true时如何更改此选项才能运行回调?
答案 0 :(得分:1)
您需要将回调指定为callable。你编写它的方式,它将始终执行你在该数组中的代码。您最好在控制器中编写专用方法。
array('deny',
'actions'=>array('index'),
'expression'=>'Yii::app()->user->isRegistered()',
'deniedCallback' => array($this, 'accessDenied'),
),
// ...
public function accessDenied()
{
$this->render('//site/info', array(
'message' => 'You must activate your account.'
));
Yii::app()->end(); // not really neccessary
}