Jump to content

What does the method Hook::exec do?


JasonWang
 Share

Recommended Posts

I dont undstand the following 2 parts. 

1. Dispatcher.php Line 345

Hook::exec('actionDispatcher', $params_hook_action_dispatcher);

 

2. Dispatcher.php Line 387

$modules_routes = Hook::exec('moduleRoutes', array('id_shop' => $id_shop), null, true, false);

 

 

The confusing thing is that the first param of the method is $hookName and if there's no such hook in DB the method will return ''.

So, the codes here do nothing, I guess. I'm not quite sure.

 

Could anyone tell me what the 2 parts exactly do here?

Share this post


Link to post
Share on other sites

 

I am not going to explain you the code line by line here, but i will explain you what the exec static member do.

When ever you call

Hook::exec("HookName");

It performs the following processes for you.

1) First it checks whether the hook is available or not? If it is not available return false;

2) Second it gets the module list for that hook from database. Also narrow down the list by exceptions for the modules for the hooks for the current page.

3) After it gets all the module(s) for the hook called for the current loaded (or called page) page, it calls the hooks function in the module. If you check modules for a specific hook you will find public function for that hook. Lets consider the Top hook. In modules you will have public functions like

public function hookTop // or public function hookDisplayTop for compatibility reasons

Please not that PS performs some other operations also there.

The above details are just giving you the idea that how hooks and modules work in PS. Also taking the above theory, i implemented the same operations in Codeigniter and Zend Framework for my own projects, and it works like a charm ;) .

If you still have any other questions, let me know and i will provide you as much details as i can.

Thank you

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More