1. 程式人生 > >ThinkPHP3.2如何設定404跳轉頁面

ThinkPHP3.2如何設定404跳轉頁面

ThinkPHP中,某一個模組或方法不存在時,自定義404頁面的方法

1、在Action目錄中新建一個檔名為EmptyAction.class.php的檔案

2、程式碼:

[php] view plaincopyprint?
  1. <?php  
  2. class EmptyAction extends Action{  
  3.     //所請求的模組不存在時,預設執行的模組
  4.     publicfunction index(){  
  5.         header("HTTP/1.0 404 Not Found");//404狀態碼
  6.         $this->display("Common:404"
    ); //顯示自定義的404頁面模版
  7.     }  
  8.     function _empty(){  
  9.         header("HTTP/1.0 404 Not Found");//404狀態碼
  10.         $this->display("Common:404");//顯示自定義的404頁面模版
  11.     }  
  12. }  
  13. ?>  
2方法2    <?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
-------------中插入***-----------
    public function _empty(){
    echo 'xxxx';
}
}