When an exception is thrown in our code like
throw new CHttpException(403, 'You are not authorized to perform this action.');
if it is a CHttpException or if YII_DEBUG is not true, the error message can be displayed by using CErrorHandler::errorAction. In the default code generated by yiic this is set to SiteController::actionError() by this settings in config/main.php
'errorHandler' => array( 'errorAction' => 'site/error', ),
in Yii versions previous to 1.1.9 exceptions was handled differently during ajax request and displayed by CApplication::displayException(). This way the exception message displayed on ajax requests could not be customized.
The message for the CGridView delete request with YII_DEBUG set to true looked like

In Yii version 1.1.9 the check for ajax request has been removed so now the exception message is handled by CErrorHandler::errorAction even during ajax requests.
This way the message can be customized for ajax requests.
by using this code
public function actionError() { if($error=Yii::app()->errorHandler->error) { if(Yii::app()->request->isAjaxRequest) echo $error['message']; else $this->render('error', $error); } }
the exception message for CGridView delete request will look like

Total 1 comment
A good idea could be to add
if some one accessing error action directly...
Leave a comment
Please login to leave your comment.