Home > Article > PHP Framework > yii custom error page
yii custom error page
1.main.php Main configuration file
'errorHandler'=>array( // use 'site/error' action to display errors 'errorAction'=>'admin/common/error', ),
The errorAction here is the controller that handles errors. Here is the error method under the common controller of the admin module
2.CommonController.php controller file
<?php /** * 通用控制器 */ class CommonController extends Controller { public function actionError() { if($error=Yii::app()->errorHandler->error) { if(Yii::app()->request->isAjaxRequest) echo$error['message']; else $this->render('error',$error); } } }
3 error.php Template file The error template file defined by the render function
<div id="mws-error-page"> <h1>Error <span><?php echo $code; ?></span></h1> <h5><?php echo CHtml::encode($message); ?></h5> </div>
where $code is the error code, and $message is the error message. Here you can Just customize the template and replace the error code and error message.
Recommended: "YII Tutorial"
The above is the detailed content of yii custom error page. For more information, please follow other related articles on the PHP Chinese website!