网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 thinkphp框架下404页面设置 仅三步
内容
    404页面即系统在找不到请求的操作方法和找不到请求的控制器名称时的一种报错行为的优化。
    在很多网站中都会有使用404页面的时候,在ThinkPHP框架中该如何设置呢,接下来我介绍其中一种方法,具体内容如下
    第一步:在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;注释掉
    以上就是thinkphp 404页面设置的全部内容,希望对大家学习php程序设计有所帮助。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/24 13:14:21