Home > PHP Framework > YII > body text

yii custom error page

angryTom
Release: 2019-11-16 14:55:35
Original
1977 people have browsed it

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',
 ),
Copy after login

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);
 }
 }
}
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template