1

我目前正在使用 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.",
        ),
    );
}

但是,如果表达式失败,我只能查看针对拒绝规则指定的消息,即“这是一条通用消息。”,即使第二次评估失败。任何实现所需行为的点都受到高度赞赏。

4

1 回答 1

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()',
),
于 2014-02-20T20:43:04.693 回答