Could someone give few tips and/or examples how Controller Plugins and Action Helpers are different? Are there situations where particular task could be accomplished with one but not another? For me they both look more or less the same and I'm often having trouble having to decide when to use what... Are there any big differences?
相关问题
- Zend Auth locked session
- Zend/PHP: Problem uploading/downloading file to/fr
- PHP Zend Framework - Zend_Config and global state
- 'Zend_Db_Statement_Exception' with message
- How to handle with foreign languages?
相关文章
- Possible disadvantages of Zend [closed]
- Zend Framework Modules with common resources
- Zend Form Validator Callback: How to exclude a use
- Exception while setting up the wurfl in zend
- How to create admin in Zend framework?
- zend framework and jquery - attach event from serv
- Magento: Programatically update cart via event
- move_uploaded_file() with Zend doens't
Action helpers also have access to the actual controlller object that's being executed. Controller Plugins only have access to the FrontController, and therefore only the controller and action name.
Which you use depends on what context you need. If you need to access a view object attached to a controller, for example, you will want an Action Helper.
A picture to illustrate the difference between plugins and action helpers: ZF Sequence Flow
Also notice that, in the front controller life-cycle process, the plugins get the control(or invoked) first than the action helpers.
Controller plugins can hook into any controller at any point in the routing process (preDispatch postDispatch, routeStartup, routeShutdown) which makes them apt at providing behind the scenes functionality like ACL enforcement.
Action Helpers are for for reusable but optional segments that your controller might need to access (redirector, flashMessenger).
So if you are creating a reusable snippet of code that always needs to execute itself then use a controller plugin, otherwise you probably want an action helper.
You can think of it this way:
So ask yourself, do I have a method that I would like to be able to call from all actions in my controller? Or do I need to add logic to the routing / dispatch process.
You might also have a look at the the Built in Action Helpers.