Home > Backend Development > PHP Tutorial > 404 page settings under thinkphp framework, thinkphp404_PHP tutorial

404 page settings under thinkphp framework, thinkphp404_PHP tutorial

WBOY
Release: 2016-07-12 08:52:54
Original
1109 people have browsed it

404 page settings under thinkphp framework, thinkphp404

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>
Copy after login

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>?>
Copy after login

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>>
Copy after login

Note: Comment out

use ThinkController;

(Complete)

http://www.bkjia.com/PHPjc/1125677.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125677.htmlTechArticle404 page settings under thinkphp framework, thinkphp404 404 page means that the system cannot find the requested operation method and cannot be found An optimization of error reporting behavior when requesting the controller name. Step one...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template