0

我有一个要求,检查当前登录的用户是否是付费会员或不是一组操作。如果用户不是付费会员,则必须将他发送到加入会员页面。以下是代码。在控制器中(Yii 框架)

public function accessRules()
{  return array(

        array('allow', 
            'actions'=>array('enroll','index','admin','suggesttags'),
            'users'=>array('@'),
            ),
        array('allow', 
            'actions'=>array('view', 'read'),
            'users'=>array(Yii::app()->user->name),
            'expression' => 'Yii::app()->controller->hasPaied()'
            ),

现在hasPayed()函数为未付费会员返回 false,目前用户被重定向到 403 异常。

我想将 403 异常页面自定义为“加入会员”页面。有没有办法做到这一点?这样从这个特定引发的所有异常controller\action都发送到获取会员页面并且其余 403 异常保持不变?

4

1 回答 1

1

尝试使用CAccessControlerFilter中的deniedCallback

// optional, the denied method callback name, that will be called once the
// access is denied, instead of showing the customized error message. It can also be
// a valid PHP callback, including class method name (array(ClassName/Object, MethodName)),
// or anonymous function (PHP 5.3.0+). The function/method signature should be as follows:
// function foo($user, $rule) { ... }
// where $user is the current application user object and $rule is this access rule.
// This option is available since version 1.1.11.
'deniedCallback'=>'redirectToDeniedMethod',
于 2013-07-08T15:34:49.813 回答