Home  >  Article  >  Backend Development  >  ThinkPHP empty modules and empty operations detailed explanation_PHP tutorial

ThinkPHP empty modules and empty operations detailed explanation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:22772browse

ThinkPHP’s empty modules and empty operations are also very practical functions. The concept of empty modules is that when ThinkPHP cannot find the specified module, it will try to locate the empty module (EmptyAction) and execute the index in the empty module. operate. In the same way, empty operations have 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 easy to understand. It is somewhat 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 realize the optimization of error pages and some URLs. The empty modules and the following are introduced in detail. How to write no operation.

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

<&#63;php
public class EmptyAction extends Action {
public function index(){
echo "当前模块不存在";
  }
 }
&#63;>

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

2. No-op , no-op is defined under the specified module. For example, we define a no-op under the User module, which is the UserAction class.

<&#63;php
class UserAction extends Action
{
public function index()
{
$this->display();
  }
public function demo(){$this->display();
  }
public function _empty(){
   //该方法即为空操作
   echo '当前操作不存在';
  }
 }
&#63;>

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824728.htmlTechArticleThinkPHP’s empty module and empty operation are also very practical functions. The concept of empty module is when ThinkPHP cannot find it. When reaching the specified module, it will try to locate the empty module (EmptyAction),...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn