What is the function of Hook in thinkphp ?? What is generally used to process the business logic?

Source: Internet
Author: User
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.

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.