Capturing all error pages like 404, 403, 500

How can i capture certain server error codes and redirect the client to the right controller? Using Yii of course.


In your main Controller just create an action:

public function actionError()


		$error = Yii::app()->errorHandler->error;



			case 404:

				// send mail later

				$this->render('error404', array('error' => $error));




and you need a layout file error404.php


<br />

<div class="errorSummary">


An Error occured during your Request:

&lt;strong&gt;ERROR &lt;?= &#036;error['code']; ?&gt;&lt;/strong&gt; The Requested Page cannot be found in the System.


&lt;p&gt;&lt;strong&gt;Message:&lt;/strong&gt; The Administrator is informed about this issue.&lt;/p&gt;



1 Like

doesn’t work, i still get:

Page Not Found

Unable to resolve the request "unittest/asf".

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster. 

what does your logs say? It works fine for me :confused:

where are my logs?

2009/09/01 13:01:23 [trace] [system.web.CModule] Loading "coreMessages" application component

2009/09/01 13:01:23 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'Unable to resolve the request "unittest/cksdvsdv".' in C:\wamp\www\webtarget\Library\Yii\web\CWebApplication.php:336

Stack trace:

#0 C:\wamp\www\webtarget\Library\Yii\web\CWebApplication.php(120): CWebApplication->runController('unittest/cksdvs...')

#1 C:\wamp\www\webtarget\Library\Yii\base\CApplication.php(133): CWebApplication->processRequest()

#2 C:\wamp\www\webtarget\index.php(32): CApplication->run()

#3 {main}

2009/09/01 13:01:23 [trace] [system.web.CModule] Loading "errorHandler" application component

how do i capture it? before it throws the exception? and all other error codes? If possible on a module basis.


Please check this out: http://www.yiiframew…de/topics.error

Read the section: Handling Errors Using an Action

I see, How do i do the same thing for each module?