Home > Backend Development > PHP Tutorial > 404 page settings under thinkphp framework thinkphp supports php5.2 thinkphp file thinkphp tags.ph

404 page settings under thinkphp framework thinkphp supports php5.2 thinkphp file thinkphp tags.ph

WBOY
Release: 2016-07-29 08:49:33
Original
886 people have browsed it

The

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

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

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

Step 2: Build a public class PublicController.class.php in Home/Comtroller in the thinkphp framework. The code is 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: where /bbs/thinkphp/404.html in header("Location:/bbs/thinkphp/404.html") is the address to which the page will jump after 404 appears. It needs to be consistent with your own 404.html page The placement corresponds.

Step 3: Let all other controllers inherit the PublicController.class.php in the second step, such as:

<?<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: Change use ThinkController;Comment out

(done)

The above introduces the 404 page settings under the thinkphp framework, including the content of thinkphp and PHP framework. I hope it will be helpful to friends who are interested in PHP tutorials.

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