Yii Framework Forum: How To Detect Which Action Generates An Error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Detect Which Action Generates An Error Rate Topic: -----

#1 User is offline   Pan_mamkkl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-September 12

Posted 17 June 2013 - 07:17 AM

I have made my custom errorHandler in this way
class MYController extends Controller{
      public function init(){
		parent::init();
                Yii::app()->errorHandler->errorAction='my/error';
      }
      public function actionError()
      {
		if($error=Yii::app()->errorHandler->error){
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->redirect(array('content/create'));
		}
	}
}

However, I don't know how to specify the reaction base on the trigger action, like I want to redirect the user to a new page when the error is triggered by actionCreate and code is 400 and display an error page when the error is is triggered by actionView
0

#2 User is offline   Artur Zhdanov 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 112
  • Joined: 12-May 13
  • Location:Russia

Posted 17 June 2013 - 08:40 AM

You can try this:
if($error=Yii::app()->errorHandler->error) {
    $actionName = $error['traces'][0]['function']; // with "action" prefix
    $controllerName = $error['traces'][0]['class'];
}

Помог с вопросом? Нажми тут ↓
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users