thinkphp Frame 404 Page setup Only three steps _php tips

Source: Internet
Author: User

404 page is the system can not find the requested operation method and can not find the requested controller name of an error behavior optimization.

In many sites will have to use 404 pages, in the thinkphp frame how to set it, next I introduce one of the methods, specific content as follows

Step One: build a EmptyController.class.php in the Home/comtroller in the thinkphp framework with the following code:

<?php
namespace HomeController;
Use Thinkcontroller;
Class Emptycontroller extends controller{
  
//null Operation _empty () method
  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");
  }
? >

Note: where header ("http/1.0 404 Not Found") is defined this status code is not 404.

Step Two: build a common class PublicController.class.php in the Home/comtroller in the thinkphp framework, with the following code:

<?php
namespace HomeController;
Use Thinkcontroller;
Class Publiccontroller extends controller{
  function _empty () {
    header ("location:/bbs/thinkphp/404.html");
  }
}
? > 

Note: the/bbs/thinkphp/404.html in header ("location:/bbs/thinkphp/404.html") is the address of the page jump after you appear 404, You need to correspond to your 404.html page placement bit.

Step three: let all other controllers inherit the PublicController.class.php in step two, such as:

<?php
namespace HomeController;
Use Thinkcontroller;
Class Indexcontroller extends Publiccontroller {public
  function index () {* * *
     }
}
? >

Note: will use Thinkcontroller; Comment out

The above is thinkphp 404 Page setup All content, hope to everybody learns PHP program design to have help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.