thinkphp框架下404頁面設(shè)置 僅三步
404頁面即系統(tǒng)在找不到請求的操作方法和找不到請求的控制器名稱時的一種報錯行為的優(yōu)化。
在很多網(wǎng)站中都會有使用404頁面的時候,在ThinkPHP框架中該如何設(shè)置呢,接下來我介紹其中一種方法,具體內(nèi)容如下
第一步:在thinkphp框架中的Home/Comtroller中建一個EmptyController.class.php,其代碼如下:
<?php
namespace HomeController;
use ThinkController;
class EmptyController extends Controller{
//空操作_empty()方法
function _empty(){
header("HTTP/1.0 404 Not Found");
$this -> display("Public:404");
}
function index(){
header("HTTP/1.0 404 Not Found");
$this -> dislay("Public:404");
}
}
?>
注意:其中 header("HTTP/1.0 404 Not Found")是定義此狀態(tài)碼未404。
第二步:在thinkphp框架中的Home/Comtroller中建一個公共的類PublicController.class.php,其代碼如下:
<?php
namespace HomeController;
use ThinkController;
class PublicController extends Controller{
function _empty(){
header("Location:/bbs/thinkphp/404.html");
}
}
?>
注意:其中 header("Location:/bbs/thinkphp/404.html")中的/bbs/thinkphp/404.html是你出現(xiàn)404后頁面跳轉(zhuǎn)的地址,需和自己的404.html頁面放置位對應(yīng)。
第三步:讓其他控制器全部繼承 第二步中的PublicController.class.php,比如:
<?php
namespace HomeController;
// use ThinkController;
class IndexController extends PublicController {
public function index(){
*
*
*
}
}
?>
注意:將use ThinkController;注釋掉
以上就是thinkphp 404頁面設(shè)置的全部內(nèi)容,希望對大家學習php程序設(shè)計有所幫助。
相關(guān)文章
phpmyadmin 3.4 空密碼登錄的實現(xiàn)方法
很多時候我們在本機測試時會將root用戶密碼設(shè)置為空。2010-05-05
PHP變量作用域(全局變量&局部變量)&global&static關(guān)鍵字用法實例分析
這篇文章主要介紹了PHP變量作用域(全局變量&局部變量)&global&static關(guān)鍵字用法,結(jié)合實例形式分析了PHP全局變量與局部變量的作用域,以及global、static關(guān)鍵字功能與使用技巧,需要的朋友可以參考下2020-01-01
PHP聚合式迭代器接口IteratorAggregate用法分析
這篇文章主要介紹了PHP聚合式迭代器接口IteratorAggregate用法,結(jié)合實例形式分析了聚合式迭代器接口IteratorAggregate的概念、功能、定義及使用方法,需要的朋友可以參考下2017-12-12
支持php4、php5的mysql數(shù)據(jù)庫操作類
2008-01-01
php中http與https跨域共享session的解決方法
這篇文章主要介紹了http與https跨域共享session的解決方法,需要的朋友可以參考下2014-12-12

