thinkphp架構下404版面設定 僅三步,thinkphp404_PHP教程

來源:互聯網
上載者:User

thinkphp架構下404版面設定 僅三步,thinkphp404


404頁面即系統在找不到請求的操作方法和找不到請求的控制器名稱時的一種報錯行為的最佳化。

在很多網站中都會有使用404頁面的時候,在ThinkPHP架構中該如何設定呢,接下來我介紹其中一種方法,具體內容如下

第一步:在thinkphp架構中的Home/Comtroller中建一個EmptyController.class.php,其代碼如下:

<?phpnamespace 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")是定義此狀態代碼未404。

第二步:在thinkphp架構中的Home/Comtroller中建一個公用的類PublicController.class.php,其代碼如下:

<?phpnamespace 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是你出現404後頁面跳轉的地址,需和自己的404.html頁面放置位對應。

第三步:讓其他控制器全部繼承 第二步中的PublicController.class.php,比如:

<?phpnamespace HomeController;// use ThinkController;class IndexController extends PublicController {  public function index(){      *    *    *     }}?>

注意:將use ThinkController;注釋掉

以上就是thinkphp 404版面設定的全部內容,希望對大家學習php程式設計有所協助。

http://www.bkjia.com/PHPjc/1127900.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1127900.htmlTechArticlethinkphp架構下404版面設定 僅三步,thinkphp404 404頁面即系統在找不到請求的操作方法和找不到請求的控制器名稱時的一種報錯行為的最佳化。...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.