
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报错处理的详细内容,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)