What is a hook? what is his role?

Source: Internet
Author: User
What is a hook? what is the function of hook? everyone knows that almost all php video lectures, including books, do not mention the Hook concept at all. However, it is often used in actual projects, so sometimes I feel that the gap in teaching practice has always been the biggest problem for Chinese people. I have never used it to talk about it, but I have never mentioned it.
After complaining, we have to face up to the grim reality. The question is, what is the hook?


Reply to discussion (solution)

Hook hooks. a set of hooks are hooks.

Hooks is a title for mounting user functions in Microsoft operating systems.
Called callable in php, the callable structure and callback function
This course should be taught.

Hook hooks. a set of hooks are hooks.

Hooks is a title for mounting user functions in Microsoft operating systems.
Called callable in php, the callable structure and callback function
This course should be taught.


Can you not use concepts to explain the concept? I didn't understand the concept in plain words. you can use this concept to explain it again.

In short, hooks are programs. These programs can be called at specific times.
Since you use the CI framework, you should know that there are some special time points in the framework initialization process, such
(1) time before framework initialization.
(2) time point before Controller initialization
(3) time points after the controller is running
Of course there are other time points.
At every point in time, you can bury some hooks (a program or a function ). In the framework, there will be a class library dedicated to hook processing (such as hooks in CI. php), The Hook class will check whether there is a specific Hook at a specific point in the program running, if there is a Hook, execute this Hook.

After talking about this, it may be a bit abstract. For example:
The whole process of your going home from work is a framework execution process. normally, you can go home directly after work. If your mom calls you and says that if you pass by the Post Office, there is a courier from another house and take it home, this process is similar to a hook (check the hook, if yes ).

If you have done some front-end work, this hook is like the "event-driven" mode.

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.