Home >Backend Development >PHP Tutorial >Setting up the 404 page under the thinkphp framework is just three steps, thinkphp404_PHP tutorial

Setting up the 404 page under the thinkphp framework is just three steps, thinkphp404_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:51:56975browse

There are only three steps to set up the 404 page under the thinkphp framework. thinkphp404

The 404 page is when the system cannot find the requested operation method and the requested controller name. Optimization of error reporting behavior.

When 404 pages are used in many websites, how to set them in the ThinkPHP framework? Next, I will introduce one of the methods. The specific content is as follows

Step one: Create an EmptyController.class.php in Home/Comtroller in the thinkphp framework. The code is as follows:

<&#63;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");
  }
}
&#63;>

Note: The header("HTTP/1.0 404 Not Found") defines this status code as 404.

Step 2: Create a public class PublicController.class.php in Home/Comtroller in the thinkphp framework, with the code as follows:

<&#63;php
namespace HomeController;
use ThinkController;
class PublicController extends Controller{
  function _empty(){
    header("Location:/bbs/thinkphp/404.html");
  }
}
&#63;> 

Note: The /bbs/thinkphp/404.html in header("Location:/bbs/thinkphp/404.html") is the page jump after you get 404 The redirected address must correspond to the location of your own 404.html page.

The third step: Let all other controllers inherit the PublicController.class.php in the second step, for example:

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

Note: Comment out use ThinkController;

The above is all the content of thinkphp 404 page settings. I hope it will be helpful for everyone to learn PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127900.htmlTechArticleThere are only three steps to set up the 404 page under the thinkphp framework. The thinkphp404 404 page means that the system cannot find the requested operation method and An optimization of error reporting behavior when the requested controller name cannot be found. ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn