开发者

Zend Framework plugins and helpers - more info

I'm trying to get my head around these issues and have been reading Zend Framework in Action (Allen), and the online documentation. It seems to me that:

  • Action Helpers provide on-demand functionality to the controller; and
  • Controller Plugins provide runtime functionality to all controllers.

Is that right?

Secondly, I see that Controller Plugins and Action Helpers can hav开发者_开发知识库e init(), preDispatch() and postDispatch() methods. In what priority do these execute, relative to those in the Action Controller itself, and to those in other plugins and Helpers?

Finally, do View Helpers have similar characteristics, or are these a different beast altogether?

Any pointers to more documentation would be much appreciated!


Action Helpers provide on-demand functionality to the controller

Action helpers provide both on-demand functionality as well as runtime functionality to all controllers via the pre and post dispatch methods.

As most developers only need to hook into these events, I often see the ZF guys (Ralph and Matthew in particular) recommending these over controller plugins.

The main difference between the two on this front is controller plugins offer a lot more hooks at various stages of the dispatch cycle.

I see that Controller Plugins and Action Helpers can have init(), preDispatch() and postDispatch() methods. In what priority do these execute, relative to those in the Action Controller itself, and to those in other plugins and Helpers?

For controller plugins, see http://framework.zend.com/manual/en/zend.controller.plugins.html (FYI, there is no init() method for controller plugins).

For controller action helpers, see http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.writingyourown

Finally, do View Helpers have similar characteristics, or are these a different beast altogether?

View helpers are similar to action helpers in that they are both marshalled by a broker but that's about the only similarity.

View helpers are essentially content generation vehicles. Under the hood, they can be as simple or complex as required but the prime objective is always string creation.


I highly recommend reading this article from Matthew - http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜