Make hooks available in code

I’ve created an application component to handle hooks.

It has some documentation inside the files, but here’s a short manual:

in the code at the place where you’d want some code to hook in (called an “entry point”):

  • Create a WEnvironment and set the desired variables.

  • set the entry point: Yii::app()->hookManager->entryPoint(‘EntryPointName’, $environment)

A hook function can be a php callback of the forms:

  • CMyClass::staticMethod($environment);

  • callbackFunc($environment);

  • WMyHook (= a class which extends WHook);

A hook can be registered with:

  • at runtime: Yii::app()->hookManager->registerHook($hook, $save); // set $save to true to save in the config file

// and never need to call this function again.

  • in the config file at protected/config/hooks.php

see the code for details about this.

Just copy these files to a place where they can be automatically loaded, like protected/components

Could or should this be part of the core framework?

Leave your thoughts about this below.

If you people think this should become an enhancement to the framework I’ll create a ticket on google projects.

Maybe i don’t get it, but can you explain, what’s the difference between Hooks and Events?

(Moved here, to not pollute the other thread. Sorry for confusion.)


Events do require listeners to subscribe. Hooks don’t. When hook is invoked, it checks all possible listeners (usually by naming


Generally hooks are a bit easier to use but they are not so performance efficient.


This is the major feature so I don’t think it can be included in 1.1.x. It’s better to keep it as an extension with good documentation and examples.

would you mind tell what to do stage-by-stage to use hook, more documents