Home  >  Article  >  PHP Framework  >  yii custom error page

yii custom error page

angryTom
angryTomOriginal
2019-11-16 14:55:351973browse

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[&#39;message&#39;];
 else
 $this->render(&#39;error&#39;,$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn