In the thinkphp framework, the 404 page is set to only three steps. thinkphp404_PHP tutorial

Source: Internet
Author: User
In the thinkphp framework, the 404 page is set to only three steps, namely, thinkphp404. In the thinkphp framework, the 404 page is set to only three steps. the thinkphp403854 page is an error message optimized when the system cannot find the requested operation method and the requested controller name. In the thinkphp framework, the 404 page is set to only three steps, and thinkphp404

The 404 page is an error message optimized when the system cannot find the requested operation method or the requested controller name.

How to set the ThinkPHP framework when using the 404 page in many websites? next I will introduce one of the methods as follows:

Step 1:In the thinkphp framework, create an EmptyController. class. php instance in Home/comtroroller. the code is as follows:

<? Phpnamespace HomeController; use ThinkController; class EmptyController extends Controller {// empty operation _ empty () method 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:Specifically, header ("HTTP/1.0 404 Not Found") defines that this status code is Not 404.

Step 2:In the thinkphp framework, create a public class PublicController. class. php with the following code:

<?phpnamespace HomeController;use ThinkController;class PublicController extends Controller{  function _empty(){    header("Location:/bbs/thinkphp/404.html");  }}?> 

Note:In the header ("Location:/bbs/thinkphp/404.html"),/bbs/thinkphp/404.html is the address of your 404houpage, which must correspond to the 404.html page Location.

Step 3:Let all other controllers inherit the PublicController. class. php in step 2, for example:

<?phpnamespace HomeController;// use ThinkController;class IndexController extends PublicController {  public function index(){      *    *    *     }}?>

Note:Comment out use ThinkController;

The above is all the content set on the thinkphp 404 page. I hope it will be helpful for you to learn about php programming.

The thinkphp404 404 page is an optimized error message when the system cannot find the requested operation method and the requested controller name ....

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.