您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

yii2 404报错处理

2025/9/17 5:09:50发布26次查看
yii2 404报错处理
frontend和backend配置方法一样,这里演示的是frontend的
1.首先进到yii框架的frontend\config文件夹下,里面有一个main.php文件,打开编辑,修改其中的控制器名和方法名:
'errorhandler' => ['erroraction' => 'common/error',],
推荐学习:yii框架
如图:
2.然后进到controllers中创建你的控制器,写入下面代码:
/** * 404友好页面 */public function actions(){return ['error' => [ 'class' => 'yii\web\erroraction', ], 'captcha' => [ 'class' => 'yii\captcha\captchaaction', 'fixedverifycode' => yii_env_test ? 'testme' : null, ,];}
如图:
3.最后在v层创建你的视图(这里是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>
如图:
以上就是yii2 404报错处理的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product