这是我在ShippingController中行为函数:
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// deny all POST requests
// [
// 'actions' => ['index', 'create'],
// 'allow' => TRUE,
// ],
[
'actions' => ['index', 'create', 'init'],
'allow' => true,
'roles' => ['user2','user3'],
'denyCallback' => function()
{
redirect to address/index if user 2 cant access redirect to address/create if user3 cant access
//redirect here
}
],
// everything else is denied
],
],
];
}
如何处理此问题!?如果角色为:user2
无法访问和重定向到address/create
,如果角色:user3
无法访问
1条答案
按热度按时间f3temu5u1#
我假设你在yii中使用的是RBAC系统。检查配置文件:
或者“yii\rbac\PHP管理器”。
以下是对我有效的方法:
规则的'allow'选项应该被设置为false,这样denyCallback才能被调用。你可以在“yiisoft/yii2/filters/AccessControl.php”的第120行看到。