What is the function of Hook in thinkphp ?? What is generally used to process the business logic? What is the function of Hook in thinkphp ?? What is generally used to process the business logic?
Reply content:
What is the function of Hook in thinkphp ?? What is generally used to process the business logic?
The hook is like a mount point and is mounted to the function. When this mount point is encountered during function execution, the hook will pull out a piece of code and execute this code. Compared with calling another function directly in a function, hook functions are more secure and convenient. When we need to modify the extension function, we do not need to modify the hook in function B, but only need to modify the code block in the hook. if we directly modify function, the class where function B is located is modified frequently. This violates the closed principle. In addition, it is more convenient to use hooks for later maintenance and function expansion.
In thinkphp, hooks are behavior extensions. The following are some online interpretations of behavior scaling:
Action
Behavior (Behavior)It is a relatively abstract concept. you can imagine an action or process in the application execution process. in the framework execution process, actions can be generated at all points, for example, routing detection is an action, static cache is an action, and user permission detection is also an action, ranging from business logic to browser detection, multi-language detection, and so on, it is even said that you want to pop up Hello, world for the first visit to your website users! These actions can be viewed as an action. the existence of actions allows you to change or add some features on the periphery without modifying the framework and application.
Different behaviors have common locations. for example, some actions are performed before the application is executed, and some actions are output after the template, we call these actions a tag. When an application runs on this tag, it is intercepted and related behaviors are executed in a unified manner.