yii2 404 error handling
The frontend and backend configuration methods are the same. The frontend is demonstrated here
1. First go to the frontend\config folder of the yii framework, there is a main.php file in it, open it for editing, and modify the controller name and method name:
'errorHandler' => [ 'errorAction' => 'common/error', ],
Recommended learning: yii framework
As shown in the picture:
2. Then go to controllers to create your controller and write the following code:
/** * 404友好页面 */ public function actions(){ return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, , ]; }
As shown:
3. Finally create your view on the V layer (here is error.php):
<?php $this->context->layout = false; //不加载公共样式 ?> <!DOCTYPE html> <html> <head> <title>404错误,您所访问的页面不存在!</title> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css"/> <link rel="stylesheet" href="css/base.css"/> </head> <body> <div id="errorpage"> <div class="tfans_error"> <div class="logo"></div> <div class="errortans clearfix"> <div class="e404"></div> <p><b>出错啦!</b></p> <p>您访问的页面不存在</p> <div class="bt" ><a href="?r=index/index">返回首页</a></div> </div> </div> </div> </body> </html>
As shown :
##
The above is the detailed content of yii2 404 error handling. For more information, please follow other related articles on the PHP Chinese website!