2013-07-07 81 views
0

我有一個要求,檢查用戶當前loged是否是付費會員或不是一組行動。如果用戶不是付費會員,那麼他必須被髮送到take member頁面。以下是代碼。在所述控制器(Yii框架)Yii框架自定義403處理特定控制器

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()函數返回假未付構件和目前用戶被重定向到403異常。

我想定製403異常頁面來'採取成員資格'頁面。有沒有辦法做到這一點?這樣從此特定controller\action引發的所有異常都會發送到take membership頁面,其餘403異常保持不變?

回答

1

嘗試使用deniedCallbackCAccessControlerFilter

// 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',