Video Learning Transcript---thinkphp---thinkphp expansion of the empty operation

Source: Internet
Author: User

An introduction to "one"

(1) Definition

An empty operation means that the system cannot find the specified action method. will be positioned to the Null action method/controller to execute, using this mechanism, we can implement error page customization and URL optimization

(2) scene

Custom that is commonly used for error pages

(3) Normal system comes with error page in two kinds

① Debug/dev Phase: Displays error message, error location, current TP version

② Generation Stage: Displays error prompt, TP version. Security has improved relative to the previous, but the user is still poor

(4) Empty operation

In view of the above situation, then you can use the empty operation mechanism for the error page beautification

(5) Description------for methods and controllers

1. Empty operation method: In the controller can define an operation method, the name is called _empty (), if the controller is not found in the method will be executed empty operation

2. Empty operation Controller: there is an empty controller in TP, if the specified controller is not found, the null controller will be accessed. The empty controller file is named EmptyController.class.php

(6) Realization:

1. Empty operation Method _empty ()

For example, the controller EmailController.class.php creates an empty method _empty (), and if the method under the access email controller does not exist, the _empty () method is called

Note: Only the empty operation method for the current controller

// Empty method         Public function _empty () {            echo "Hello, page does not exist oh ^_^, ie". Action_name. "Operation does not exist";        }

At this time the browser URL input does not exist template email controller under the index.html template, the browser error prompts as follows

Common system constants: http://570109268.iteye.com/admin/blogs/2415438

2. Empty controller EmptyController.class.php

<? php    namespace Admin\controller;      Use Think\controller;     class extends controller{        publicfunction  _empty () {            echo " The page visited does not exist, the empty controller ";        }    }? >

The next step is to access the NULL Controller + NULL method, at which time the null controller's processing method is called first. Below access the null controller AAA, under the empty method AAA

(7) Case: Using empty operation method to achieve 404 page customization

Analysis:

First step: Create an empty operation controller and an empty method

NULL controller EmptyController.class.php; Null operation method: _empty ()

Step two: Show static pages

Copy the error template page to the specified location application\admin\view\empty\error.html, modify the static resource path

Step Three:

Empty operation method in the empty controller, showing the wrong template page

①emptycontroller.class.php:

<? php    namespace Admin\controller;      Use Think\controller;     class extends controller{        publicfunction  _empty () {            $this Display (' empty/error ');//error page show        }    }?>

② when the controller is present, the method does not exist to access the _empty () method under the controller

For example, to access the AAA method under the email controller, the _empty method under the email controller is called. So you have to modify the method

EmailController.class.php:

// Empty method         Public function _empty () {            //  echo "Hello, page does not exist oh ^_^, ie". Action_name. "Operation does not exist";            $this->display (' Empty/error ');        }

.

Video Learning Transcript---thinkphp---thinkphp expansion of the empty operation

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.