我目前正在使用yii 1.1.10版本,我试图通过在accessRules函数中定义消息来指定特定于规则的错误消息,如下所示:
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('xxx','yyy'),
'users'=>array('*'),
),
array('allow', // allow all users to perform 'index' and 'view' actions
'message'=>'You must be logged in as Member to perform this action.',
'actions'=>array('zzz','aaa',),
'expression'=>'AuthenticationHelper::isSessionUserAdmin()',
),
array('deny', // deny all users
'users'=>array('*'),
'message' => "This is a generic message.",
),
);
}
但是,如果表达式失败,我只能查看针对拒绝规则指定的消息,即“这是一般消息。”,即使第二次评估失败也是如此。任何达到理想行为的要点都受到高度赞赏。
答案 0 :(得分:0)
你可以这样做:
array('allow',
'message'=>'You must be logged in as Member to perform this action.',
'actions'=>array('zzz','aaa',),
'expression'=>'AuthenticationHelper::isSessionUserAdmin()',
),
array('deny',
'message'=>'You must be logged in as Member to perform this action.',
'actions'=>array('zzz','aaa',),
'expression'=>'!AuthenticationHelper::isSessionUserAdmin()',
),