thinkphp empty module and empty operation detailed _php tutorial

Source: Internet
Author: User
thinkphp empty module and empty operation is also a useful function, the concept of empty module is when thinkphp can not find the specified module, it will attempt to locate the empty module (emptyaction), the empty module inside the index operation. Similarly, the empty operation is 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, very good understanding, a bit like the PHP virtual host inside the custom 404 page, but it is more flexible than the custom 404, using this mechanism, we can implement the error page and some URL optimization, the following detailed description of the next empty module and empty operation.

1. Empty module , define the Emptyaction class in the project:

<?phppublic class Emptyaction extends Action {public Function index () {echo "current module does not exist";  }}? >

This is a simple empty module class, of course, you can also do some more complex operations, everything must be written according to the needs of the project, here is just a demonstration.

2. Empty operation, the empty operation is defined under the specified module, for example, we define an empty operation under the user module, which is the Useraction class.

<?phpclass Useraction extends Action{public function index () {$this->display ();  } Public Function Demo () {$this->display ();  } Public Function _empty () {   //the method is empty operation   Echo ' current operation does not exist ';  }? >

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

http://www.bkjia.com/PHPjc/824728.html www.bkjia.com true http://www.bkjia.com/PHPjc/824728.html techarticle thinkphp Empty module and empty operation is also a very useful function, the concept of empty module is when thinkphp can not find the specified module, it will try to locate the empty module (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.