• 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;注释掉

    (完成)

  • 相关阅读:
    2017年年终总结
    7只老鼠测试100个瓶子
    jgs--多线程和synchronized
    springboot&&vue简单的景点信息管理系统
    springboot&&vue前后端分离入门案例
    npm安装教程
    springboot整合mybatisplus
    spring整合Mybatis-plus
    Springboot简单练手的记账本
    SpringBoot整合thymeleaf简单的CRUD
  • 原文地址:https://www.cnblogs.com/wenzheshen/p/5485627.html
Copyright © 2020-2023  润新知