Kohana events, where to place them
Question
I'm trying to understand the event system of Kohana. The only thing i don't understand is, where to place the Event::add code.
It should be in a place where it is executed before any events are fired. Or am I missing something?
What i want to achieve is to construct a class that is available everywhere, but don't realy want to hack it into Kohana.
Can anyone cast a light on this?
Solution
Try adding in a hook with your Event::Add code.
From the documentation:
The power of hooks mainly comes from the Events class. Hooks are loaded before any of the events are started so you can attach a hook to an event
OTHER TIPS
Usually Event::add() and Event::replace() are placed in the Hook constructor. Hooks are loaded before the first event of system ('system.ready') so you can add your callback to every system or custom event.