ThinkPHP empty module and empty Operation Details

Source: Internet
Author: User

ThinkPHP's empty module and empty operation are also very useful functions. The concept of empty module is that when ThinkPHP cannot find the specified module, it will try to locate the empty module (EmptyAction ), perform the index operation in the empty module. Similarly, empty operations are the same concept. When the system cannot find the operation method under the specified module, it will try to locate the empty operation method (empty ). In fact, it is a bit similar to the custom 404 page in the php virtual host, but it is more flexible than the custom 404, using this mechanism, we can optimize the error page and some URLs. The following describes the empty module and empty operation methods in detail.

1. Empty Module, Define the EmptyAction class in the project:

<? Phppublic class EmptyAction extends Action {public function index () {echo "the current module does not exist" ;}}?>

This is a simple empty module class. Of course, you can also perform more complex operations in it. Everything has to be written according to the project requirements. Here is just a demonstration.

2. Empty operationAn empty operation is defined under the specified module. For example, we define an empty operation under the User module and the UserAction class.

<? Phpclass UserAction extends Action {public function index () {$ this-> display ();} public function demo () {$ this-> display ();} public function _ empty () {// This method is null Operation echo 'current operation does not exist'; }}?>

The code is very simple. This is an empty method, and empty modules and empty operations can be used at the same time to complete more complex operations.

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.