zoukankan      html  css  js  c++  java
  • thinkphp框架下404页面设置

    404页面即系统在找不到请求的操作方法和找不到请求的控制器名称时的一种报错行为的优化。

    第一步:在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")是定义此状态码未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是你出现404后页面跳转的地址,需和自己的404.html页面放置位对应。

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

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

    注意:将use ThinkController;注释掉

    (完成)

  • 相关阅读:
    JVM系列(五)并发相关
    String的hashCode 和equals 区别
    JVM系列(四)生命周期和classloader
    jvm面试题解答
    memcached(十三)注意事项
    memcached(十二)监控
    memcached(十)动态扩容
    memcached(九)--LRU
    memcached(八)-- set指令内部实现
    用通俗易懂的大白话讲解Map/Reduce原理
  • 原文地址:https://www.cnblogs.com/wenzheshen/p/5485627.html
Copyright © 2011-2022 走看看