How to customize 500 error in yii2
1. Create ErrorHandler, inherit this yii\base\ErrorHandler abstract class, and then define the abstract method in this parent class
<?php namespace common\component\exception; /** * User: szliugx@gmail.com * Date: 2016/9/20 * Time: 14:24 */ use yii; use yii\base\ErrorHandler as BaseErrorHandler; use common\component\earlywarning\EarlyWarning; class ErrorHandler extends BaseErrorHandler { public $errorView = '@app/views/errorHandler/error.php'; public function renderException($exception) { if(Yii::$app->request->getIsAjax()){ exit( json_encode( array('code' =>$exception->getCode(),'msg' =>$exception->getMessage()) )); }else{ //将500的代码,发送监控预警 if(!empty($exception->getCode()) && $exception->getCode() ==8){ $params = []; $params['projectName'] = "oct-youban"; $params['level'] = 5; $params['title'] = "500:".$exception->getMessage(); $params['value'] = $exception->getCode(); $params['message'] = $exception->getFile().":".$exception->getLine(); $params['bizcode'] = 8; $params['subcode'] = 8001; EarlyWarning::WarninApi($params); } echo Yii::$app->getView()->renderFile($this->errorView,['exception' => $exception,],$this); } } }
Recommended tutorial: yii Framework
2. Create the view file: @app/views/errorHandler/error.php
<?php /** * User: szliugx@gmail.com * Date: 2016/9/20 * Time: 15:23 */ ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <meta http-equiv="Expires" content="-1"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Pragma" content="no-cache"> <title><?php if(!empty($exception->getCode())&&($exception->getCode() == 8)){echo "出错啦";}else{ echo $exception->getMessage();}?></title> <link href="/css/error.css" rel="stylesheet" 0="frontend\assets\AppAsset"> </head> <body> <div> <div class="status-icon icon-desk"></div> <div> <p><?php if(!empty($exception->getCode())&&($exception->getCode() == 8)){echo "出错啦";}else{ echo $exception->getMessage();}?></p> </div> </div> </body> </html>
3. Modify the application configuration file: @app/config/main.php
'errorHandler' => [ //'errorAction' => 'site/error', 'class' => 'common\component\exception\ErrorHandler', ],
The effect is as follows:
500 error page:
Programming Introduction column on the php Chinese website!
The above is the detailed content of How to customize 500 error in yii2. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

This article will introduce you to the yii2 framework, share a few CTF exercises, and use them to learn the yii2 framework. I hope it will be helpful to everyone.

500internal server error means HTTP 500 internal server error, which means that the server encountered an unexpected situation that caused it to be unable to fulfill the request, but it cannot explain the specific error or the root cause of the error; when an error occurs, the website visited will display an error. .

1. You need to download the windows version of the master branch of yii2-redis with composer 2. Unzip and copy it to vendor/yiisoft 3. Add 'yiisoft/yii2-redis'=>array('name'=>'yiisoft to extensions.php under yiisoft /yii2-redis','version'=>'2.0.

Ethereum price started a recovery wave above the $2,250 level. ETH was able to clear the $2,280 resistance zone to move into a positive zone, but momentum was weak compared to Bitcoin.

According to one expert, the 2011 piece was minted to celebrate the London Olympics in 2012

Bitcoin has initiated a significant upward movement, surpassing the $57,500 resistance level and now showing promising signs of potentially reaching the $60,000 mark.

New players can claim the BetMGM welcome bonus and get up to $1,500 paid back in bonus bets by using promo code MLIVEMGM.
