欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

thinkphp框架下404頁面設(shè)置 僅三步

 更新時間:2016年05月14日 17:12:36   作者:申文哲  
這篇文章主要為大家詳細(xì)介紹了ThinkPHP 404頁面的設(shè)置方法,僅需要三步實現(xiàn)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)容,希望對大家學(xué)習(xí)php程序設(shè)計有所幫助。

相關(guān)文章

最新評論