thinkphp 404 Page Setup

Source: Internet
Author: User

Direct definition of empty modules and empty operations, that is, to establish a EmptyAction.class.php,


<?php
. 
03.class Emptyaction extends Action {
. 
05.function _empty () {
06.header ("http/1.0 404 Not Found");
$this->display (' public:404 ');
. 
10.//404
11.function Index () {
12.header ("http/1.0 404 Not Found");
$this->display (' public:404 ');
.
. 
18.?>


It is important to set the header header, otherwise the return status will be 200.

This class corresponds to a page template named 404 under the Public template directory.

In addition to creating a emptyaction empty module, you have to create a _empty method within each controller.  Inside each controller. Of course, you can use common classes to avoid such repetitive operations.
Establish a common class controller: CommonAction.class.php

<?php
Class Commonaction extends action{
function _empty () {
Header ("Location:/404.html");
}
}
?>

Then let the other controller inherit this controller, such as indexaction extends Commonaction this is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.