我正在做一个需要身份验证的应用程序。在应用程序的索引页面中,我指定了这样的访问规则
public function accessRules() {
return array(
array('deny',
'actions'=>array('index','register','login','password'),
'users'=>array('@'),
),
array('allow',
'users'=>array('*')
),
);
}
在第一条规则中,'index'、'register'、'login' 和 'password' 操作对于经过身份验证的用户来说是不可访问的。但是,我不想显示此消息
Unauthorized
You are not authorized to perform this action.
You do not have the proper credential to access this page.
If you think this is a server error, please contact the webmaster.
...当经过身份验证的用户尝试访问这些操作时。相反,我想将它们重定向到另一个页面。如果我能在第一条规则上做这样的事情,那将很有用
array('redirect',
'actions'=>array('index','register','login','password'),
'users'=>array('@'),
'url'=>array('home/index'),
),
最佳答案
从 Yii v1.1.11 开始,你可以用回调和闭包做同样的事情,而且只需要默认类:
array('deny',
'actions'=>array('index','register','login','password'),
'users'=>array('@'),
'deniedCallback' => function() { Yii::app()->controller->redirect(array ('/home/index')); }
),
关于php - 使用 Yii 重定向访问规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9804751/