^Status|Stub| ^Todo|What events are, how events work, running, adding, using custom| ^Todo|Move stuff from core:event | ====== Events ====== See [[core:event|Event]] for information on adding, running, removing and using custom events. Kohana events consist of a **name** and [[http://php.net/manual/en/language.pseudo-types.php#language.types.callback|callback]]. Names usually include a prefix with the name ((An example of a "prefix" is prefix.name)), but are not required to. All of the core events are prefixed as ''system.name''. ===== System Events ===== The following events are defined in the Kohana core files. The pre-defined actions for these events are added in [[core:kohana#setup|Kohana::setup]]. === system.ready === Called immediately after hooks are loaded. This is the earliest attachable event. Nothing is attached to this event by default. Hooks are loaded before this point. === system.routing === Processes the URL and does routing. Calls [[libraries:router#setup|Router::find_uri]] and [[libraries:router#setup|Router::setup]] by default. === system.execute === Controller locating and initialization. A controller object will be created, as an instance of Kohana. Calls [[core:kohana#instance|Kohana::instance]] by default. === system.post_routing === Triggered after all routing is done so interventions in routing can be done here. If Router::$controller is empty after this event a 404 is triggered. === system.404 === Called when a page cannot be found. Calls [[core:kohana#show_404|Kohana::show_404]] by default. === system.pre_controller ==== Called within system.execute, after the controller file is loaded, but before an object is created. === system.post_controller_constructor === Called within [[#system.execute|system.execute]], after the controller constructor has been called. [[core:kohana#instance|Kohana::instance]] will return the controller at this point, and views can be loaded. Controller methods have not been called yet. === system.post_controller === Called within [[#system.execute|system.execute]], after the controller object is created. [[core:kohana#instance|Kohana::instance]] will return the controller at this point, and views can be loaded. === system.send_headers === Called just before the global output buffer is closed, before any content is displayed. Writing cookies is not possible after this point, and [[libraries:session|Session]] data will not be saved. === system.display === Displays the output that Kohana has generated. Views can be loaded, but headers have already been sent. The rendered output can be manipulated as [[core:event#data|Event::$data]]. === system.shutdown === Last event to run, just before PHP starts to shut down. Runs the Kohana::shutdown method by default. === system.log === Called within [[core:kohana#methods_log|Kohana::log]], useful if you want to send an email when certain events are logged or store log messages in a different location. === system.redirect === Called within [[helpers:url#redirect|url::redirect]], useful to detect that the system is about to perform a redirect. ===== Events Sequence ===== [[http://brotkin.ru/examples/kohana_docs/kohana_sequences_eng.png|{{http://brotkin.ru/examples/kohana_docs/kohana_sequences_eng.png}}]] ===== Hooks ===== Hooks are included early in Kohana and can be used, e.g., to execute code before controllers are loaded so you can check for authentication early on in processing and thereby reduce server resources. Events and hooks go hand in hand: hooks allow you to attach code to events. See for more information the [[general:hooks|Hooks]] page.