^Status|Draft| ^Todo|More examples, proof read| ====== Hooks ====== Hooks are basically files included at the start of Kohana, to be more specific they are loaded in the Kohana::setup() method. At this time these files are loaded, so their methods can be used * index.php * core/Bootstrap.php * core/Benchmark.php * core/utf8.php * core/Event.php * core/Kohana.php No **event** has been started yet, the first to be started is **system.ready** Hook files should be put in ''application/hooks'' or similarly in a module folder. ===== Configuring hooks ===== To configure hooks edit ''config.php'' in your application/config directory. Look the option like this: **File: config.php** $config['enable_hooks'] = FALSE; Set ''$config['enable_hooks']'' to ''TRUE'' and all files in the hooks directory (''application/hooks'') will be included and the code will be executed. **Example** config.php //To include all files in application/hooks $config['enable_hooks'] = TRUE; ===== Hooks and events ===== The power of hooks mainly comes from the [[core:event|Events]] class. Hooks are loaded before any of the events are started. This means you can use a hook to modify an event's callbacks. For example you could load the following file as a hook **Example** hooks/power.php class Power { public function Kohana(){ Event::$data = Event::$data.''; } } Event::add('system.display', array('Power', 'Kohana')); This will add a callback to the the system.display event. The callback is to the method Power::Kohana. Power::Kohana adds a small notice to the bottom of each page (). It utilizes the Event::$data to manipulate the final output. See [[core:event#data|Events]] for details. ===== Constants ===== When using hooks you might need to get under the hood of Kohana. When the hooks are loaded these constants are set in index.php * EXT - contains the default file extension used for files in Kohana. Defaults to '.php' * KOHANA - basename * DOCROOT - dirname * APPPATH - path to the application directory * SYSPATH - path to the system directory * MODPATH - path to the modules directory