Zend_Controller_Plugin_Abstract,用户插件应当从这个类继承:
routeStartup() 在 Zend_Controller_Front
向注册的 路由器 发送请求前被调用。
routeShutdown() 在 路由器
完成请求的路由后被调用。
dispatchLoopStartup() 在 Zend_Controller_Front
进入其分发循环(dispatch loop)前被调用。
preDispatch() 在动作由 分发器
分发前被调用。该回调方法允许代理或者过滤行为。通过修改请求和重设分发标志位(利用
Zend_Controller_Request_Abstract::setDispatched(false)
)当前动作可以跳过或者被替换。
postDispatch() 在动作由 分发器
分发后被调用。该回调方法允许代理或者过滤行为。通过修改请求和重设分发标志位(利用
Zend_Controller_Request_Abstract::setDispatched(false)
)可以指定新动作进行分发。
dispatchLoopShutdown() 在 Zend_Controller_Front
推出其分发循环后调用。
Zend_Controller_Plugin_Abstract
即可编写插件类。
Zend_Controller_Plugin_Abstract 的全部方法都不是抽象的,
这意味着插件类并不是一定要去实现前面列出的每一个事件方法。
插件的开发者只要实现需要用到的方法即可。
Zend_Controller_Plugin_Abstract 也可以通过调用
getRequest() 和 getResponse()
方法从控制器中分别获取 request 对象和 response 对象.
Zend_Controller_Front::registerPlugin() 在任何时候注册插件类。
下面的代码片段说明了如何在控制器链条中使用插件。
routeStartup() called
\n"); } public function routeShutdown(Zend_Controller_Request_Abstract $request) { $this->getResponse()->appendBody("routeShutdown() called
\n"); } public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { $this->getResponse()->appendBody("dispatchLoopStartup() called
\n"); } public function preDispatch(Zend_Controller_Request_Abstract $request) { $this->getResponse()->appendBody("preDispatch() called
\n"); } public function postDispatch(Zend_Controller_Request_Abstract $request) { $this->getResponse()->appendBody("postDispatch() called
\n"); } public function dispatchLoopShutdown() { $this->getResponse()->appendBody("dispatchLoopShutdown() called
\n"); } } $front = Zend_Controller_Front::getInstance(); $front->setControllerDirectory('/path/to/controllers') ->setRouter(new Zend_Controller_Router_Rewrite()) ->registerPlugin(new MyPlugin()); $front->dispatch(); ]]>routeShutdown() called
dispatchLoopStartup() called
preDispatch() called
postDispatch() called
dispatchLoopShutdown() called
]]>getPlugin($class) 允许获取指定类名的一个插件。
如果没有插件匹配,将返回 false。如果有多个指定类的插件被注册,则返回一个数组。
getPlugins() 返回全部插件。
unregisterPlugin($plugin) 允许从插件列表中移除一个插件。
传递一个插件件对象,或者需要移除的插件的类名。如果传递类名,任何该类的插件都将被移除。