状态 草稿
Todo What events are, how events work, running, adding, using custom
Todo Move stuff from core:event
官方最后更新时间 2009/01/30 08:41

事件(Events)

关于事件的添加,运行,删除,自定义事件详细信息请看 事件类(Event Class)

Kohana 事件的组成是由事件名callback 组成1)。事件名一般带有前缀。但这不是必须,所有的 核心库(Core)事件 都是以 system 为前缀,例如:system.name

系统事件(System Events)

下列事件的定义均在 Kohana 核心库文件中。为这些事件预定义的动作均在 Kohana::setup 中。

system.ready

当钩子(hooks )加载后立即调用此事件。这个事件是最早可捕捉的事件。钩子加载之前,默认情况下没有附加到这个事件上。

system.routing

运行过程中网址是否路由。默认情况下调用 Calls Router::find_uriRouter::setup

system.execute

控制器的定位和初始化。当控制器对象作为 Kohan 实例被创建时,默认情况下调用 Kohana::instance

system.post_routing

在所有的 routing 执行完成后触发此事件,如果 Router::$controller 为空则触发 404 事件。

system.404

当页面没有找到时调用此事件。默认情况下调用 Kohana::show_404

system.pre_controller

在控制器加载之后但在对象创建之前同 system.execute 一起调用。

system.post_controller_constructor

在控制器的构造器被调用后同 system.execute 一起调用。Kohana::instance 在这点返回控制器。控制器方法

Called within system.execute, after the controller constructor has been called. 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, after the controller object is created. 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 Session data will not be saved.

system.display

:?:显示输出 Kohana 系统已经运行。视图被加载,但是头信息(headers )已经发送。rendered 输出可以作为被操纵的,就像 Event::$data

原文: Displays the output that Kohana has generated. Views can be loaded, but headers have already been sent. The rendered output can be manipulated as Event::$data.

system.shutdown

PHP 结束(关闭)之前最后运行的事件,默认情况下运行 Kohana::shutdown 方法。

system.log

Kohana::log 一起调用。如果你想在不同的地方记录或存储某些事件的日志信息使用它发送邮件是一个不错的方式。

system.redirect

url::redirect 一起调用。可以很好的用于系统执行重定向。

钩子(Hooks)

:?:钩子在 Kohana 系统运行前期加载,它可以执行代码前被使用,举例说,控制器被加载这样您就可以检查相关事项(比如在 Kohana 系统运行前期进行验证)。事件和钩子可以配合使用。相辅相成的。详情请参见 钩子(Hooks) 页面。

原文: Hooks are included early in Kohana and can be used to execute code before e.g. controllers are loaded so you can check for for example authentication early in Kohana. Events and hooks go hand in hand since in hooks you can attach code to events. See for more information the Hooks page.

1) 例如:prefix.name 的前缀就 “prefix”
general/events.txt · 最后更改: 2009/02/02 23:00 由 icyleaf