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:
<?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"); } } ?>
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:
<?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 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:
<?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.