I want to display 404 error page for that i have made error404.php file in my protected/view/system folder.
By default i have Sitecontroller and it contained error acti
Use this code for actionError:
$app = Yii::app();
if( $error = $app->errorHandler->error->code )
{
if( $app->request->isAjaxRequest )
echo $error['message'];
else
$this->render( 'error' . ( $this->getViewFile( 'error' . $error ) ? $error : '' ), $error );
}
In views/site create error404.php for 404 errors and error.php for the rest.
Or you can define param in the config for errors you like to handle differently and check error code against it:
$app = Yii::app();
if( $error = $app->errorHandler->error->code )
{
if( Yii::app()->request->isAjaxRequest )
echo $error['message'];
else
$this->render( 'error' . ( in_array( $error, $app->params[ 'customErrorPages' ] ) ? $error : '' ), $error );
}
Error handler works like this: when httpexception arise, component will check if there is any value in errorAction property and if there is any, will run this controller's action. If there is no set value to the errorAction property, will display error view from system folder. So there is no need to mix error views from system view folder and controller's view folder.