1.processRegistrationAction() 形式的Action 要用
http://www.example.org/member/process-registration
形式的URL访问
2.插件
插件会对任何请求做出响应,并不关心具体的controller,插件只需要front Controller(前端控制器)注册即可.
此外,对于插件而言,所有的代码都包含在 preDispatch() 或 postDispatch()方法里面.
//插件调用时机 front::dispatch(){ //... do { $this->_request->setDispatched(true); /** * Notify plugins of dispatch startup */ $this->_plugins->preDispatch($this->_request); /** * Skip requested action if preDispatch() has reset it */ if (!$this->_request->isDispatched()) { continue; } /** * Dispatch request */ try { $dispatcher->dispatch($this->_request, $this->_response); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->_response->setException($e); } /** * Notify plugins of dispatch completion */ $this->_plugins->postDispatch($this->_request); } while (!$this->_request->isDispatched()); //... }
3.helper
3.1助手也可以在动作前或后添加一些辅助功能.
3.2 助手有一个direct()方法,当直接调用助手时,direct 方法会被调用。直接调用是指用以下方式调用
$this->_helper->myHelper("Ping");
3.3 Zend_Controller_Action_HelperBroker 助手会在任何控制器初始化时加载,然后初调用来显示脚本模板.
public function Zend_Controller_Action::__construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) { $this->setRequest($request) ->setResponse($response) ->_setInvokeArgs($invokeArgs); $this->_helper = new Zend_Controller_Action_HelperBroker($this); $this->init(); }
//helper 调用时机 dispatcher::dispatch()->Action::dispatch(); Action::dispatch($action) { // Notify helpers of action preDispatch state $this->_helper->notifyPreDispatch(); $this->preDispatch(); if ($this->getRequest()->isDispatched()) { if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) { if ($this->getInvokeArg('useCaseSensitiveActions')) { trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"'); } $this->$action(); } else { $this->__call($action, array()); } $this->postDispatch(); } // whats actually important here is that this action controller is // shutting down, regardless of dispatching; notify the helpers of this // state $this->_helper->notifyPostDispatch(); }
从插件与助手的调用时机可以看出:
1。插件是在控制器转发“前” 就由前端控制器进行调用,因此它的作用域是在前端,对所有的控制器都是有效的
2。助手是在控制器转发“后” 由动作调用的,因此它的作用域只限于某一动作内