這篇文章將為大家詳細講解有關yii如何返回404,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
1、首先進到yii框架的frontend\config文件夾下,里面有一個main.php文件,打開編輯,修改其中的控制器名和方法名:

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

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;}
h2{ font-size:40px; margin-bottom:35px; }
</style>
</head>
<body>
<div id="mother">
<div id="errorBox">
<div id="errorText">
<h2>Sorry..頁面沒有找到!</h2>
<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>關于“yii如何返回404”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。