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