THINKPHP5 Note Seven: Set error page ②

Source: Internet
Author: User

More perfect to set the error page.

First, prepare an error page error.html, location: thinkphp\template\index\default\error.html, ready to point to all the previous error hints.

Two, empty operation Point

In apps\index\controller\indexbase.php, the "base class" is set _empty

<? PHP /*  */namespace  app\index\controller;use  app\common\controller\base; class Indexbase extends  base{    public  function _initialize ()    {        parent::_initialize ();    }     /* *     * Empty operation Jump      */public       function _empty ()        {//  abort ();              exception ();     Both  of these methods are possible    }}

Three, NULL controller point

In apps\index\controller\error.php

<? PHP /*  */namespace  app\index\controller;use App\index\controller; class Error extends indexbase{    public  function Index () {        abort ();}    }

Four, abnormal error point

The index/config.php exception_tmpl parameter.

' Exception_tmpl '         ' TPL ' ' THINK_EXCEPTION.TPL '  //' exception_tmpl ' = ' e:/wamp/www/thinkphp/template/index/default/error.html ', 

Note: The address must be an absolute path.

Expand

401,404,500 error Page Customization

Related parameters: Http_exception_template

Manual Address: http://www.kancloud.cn/manual/thinkphp5/163256

Code:

config.php

'http_exception_template'=  [        //defines the redirect page address for the 404 error        404= Root_path.config ('Template.view_path'). config ('Index.model_name').'/'. config ('index.default_template').'/404.html',        //You can also define other HTTP status        401= Root_path.config ('Template.view_path'). config ('Index.model_name').'/'. config ('index.default_template').'/401.html',    ],

Controller call

Abort (404, ' Error message ')

Error.html,404.html page code, you can refer to Thinkphp\thinkphp\tpl\think_exception.tpl

THINKPHP5 Note Seven: Set error page ②

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.