404 page means the system cannot find the requested operation method and the requested controller name An optimization of error reporting behavior.
Step one: Create an EmptyController.class.php in Home/Comtroller in the thinkphp framework. The code is as follows:
<span><?php<br />namespace Home\Controller;<br />use Think\Controller;<br />class EmptyController extends Controller{<br /> <br /> //空操作_empty()方法<br /> function _empty(){<br /> header("HTTP/1.0 404 Not Found");<br /> $this -> display("Public:404");<br /> }<br /> <br /> function index(){<br /> header("HTTP/1.0 404 Not Found");<br /> $this -> dislay("Public:404");<br /> }<br />}<br />?></span><span><br /></span>
Note: 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:
<?<span>php namespace Home\Controller; </span><span>use</span><span> Think\Controller; </span><span>class</span> PublicController <span>extends</span><span> Controller{ </span><span>function</span><span> _empty(){ </span><span>header</span>("Location:/bbs/thinkphp/404.html"<span>); } } </span>?>
Note: /bbs/thinkphp/404.html< in header("Location:/bbs/thinkphp/404.html") 🎜> is the address where the page jumps after you get a 404, and it needs to correspond to the placement of your own 404.html page.
Step 3: Let all other controllers inherit the PublicController.class.php in step 2, for example:
<?<span>php namespace Home\Controller; </span><span>//</span><span> use Think\Controller;</span> <span>class</span> IndexController <span>extends</span><span> PublicController { </span><span>public</span> <span>function</span><span> index(){ </span>* * *<span> } } ?</span>>
Note: Comment out
use ThinkController;
(Complete)