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.