What is the role of the hook function in thinkphp? What business logic is generally used for processing?

Source: Internet
Author: User
What is the role of the hook function in thinkphp? What business logic is generally used for processing?

Reply content:

What is the role of the hook function in thinkphp? What business logic is generally used for processing?

A hook is like a mount point that hangs on a function. When this mount point is encountered during the execution of the function, the hook pulls a piece of code out and executes the code. The hook function is more secure and convenient than calling another function directly in the function. When we need to modify the extension function, we do not need to modify the hooks in function B, just modify the code block inside the hook, and if you modify function a directly, the class of function B is changed frequently. Violates the principle of closure. Another point, the use of hooks for later maintenance and functional expansion more convenient.

Thinkphp inside, the hook is the behavior extension. Here are some of the online explanations for behavior extensions:

Behavior

behavior (Behavior) is a relatively abstract concept that you can imagine as an action or a process in the execution of an application, where each position can have a behavior, such as a route detection is a behavior, a static cache is a behavior, User rights detection is also behavior, large to business logic, small to browser detection, multi-language detection and so can be regarded as a behavior, even say you want to give your site users the first access to pop hello,world! These can be seen as a behavior where the presence of the behavior allows you to change or add functionality to the perimeter by extending or configuring it without altering the framework and application.
And the different behavior also has the position common, for example, some behavior's function position all is before the application executes, some behavior is after the template output, we call these behavior function the place to be labeled (bit), when the application runs to this label, will be intercepted, Uniform execution of related behaviors

  • 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.