登录  /  注册
首页 > php框架 > YII > 正文

yii怎么返回404

爱喝马黛茶的安东尼
发布: 2019-11-09 10:00:50
原创
2881人浏览过

yii怎么返回404

1、首先进到yii框架的frontend\config文件夹下,里面有一个main.php文件,打开编辑,修改其中的控制器名和方法名:

f525c5de5a30e0646a7f8f7553f6571.png

2、然后进到controllers控制器中,在控制器code里面添加error方法。

d460746221bb15c584decdfafd4f0f1.png

3、最后在V层创建你的视图(这里是error.php):

<?php
use yii\helpers\Html;
$this->title = $name;
$this->context->layout = false; //不使用布局,或者改为自己所需要使用的布局
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <title>这个.. 页面没有找到!!!_SJ5D.COM</title>
    <style type="text/css">
        body{ margin:0; padding:0; background:#efefef; font-family:Georgia, Times, Verdana, Geneva, Arial, 
        Helvetica, sans-serif; }
        div#mother{ margin:0 auto; width:943px; height:572px; position:relative; }
        div#errorBox{ background: url(/404_bg.png) no-repeat top left;width:943px; height:572px;margin:auto;}
        div#errorText{ color:#39351e; padding:146px 0 0 446px }
        div#errorText p{ width:303px; font-size:14px; line-height:26px; }
        div.link{ /*background:#f90;*/ height:50px; width:145px; float:left; }
        div#home{ margin:20px 0 0 444px;}
        div#contact{ margin:20px 0 0 25px;}
        h1{ font-size:40px; margin-bottom:35px; }
    </style>
</head>
<body>
<div id="mother">
    <div id="errorBox">
        <div id="errorText">
            <h1>Sorry..页面没有找到!</h1>
            <p>
                似乎你所寻找的网页已移动或丢失了。
            <p>或者也许你只是键入错误了一些东西。</p>
            请不要担心,这没事。如果该资源对你很重要,请与管理员联系。
            </p>
            <p>
                火星不太安全,我可以免费送你回地球
            </p>
        </div>
        <a href="http://www.baidu.com" title="返回SJ5D首页">
            <div class="link" id="home"></div>
        </a>
        <a href="http://www.aliyun.com" title="联系管理员">
            <div class="link" id="contact"></div>
        </a>
    </div>
</div>
</body>
</html>
登录后复制

php中文网,大量的免费yii入门教程,欢迎在线学习!

以上就是yii怎么返回404的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号