ThinkPHP empty module and empty operation details _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
ThinkPHP empty module and empty operation details. 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 ), 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.

Values (EmptyAction ),...

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.