Zend Framework: Controller Plugins vs Action Helpers

后端 未结 5 596
不知归路
不知归路 2020-12-13 14:21

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 on

相关标签:
5条回答
  • 2020-12-13 14:58

    Also notice that, in the front controller life-cycle process, the plugins get the control(or invoked) first than the action helpers.

    0 讨论(0)
  • 2020-12-13 14:59

    A picture to illustrate the difference between plugins and action helpers: ZF Sequence Flow

    0 讨论(0)
  • 2020-12-13 15:09

    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.

    0 讨论(0)
  • 2020-12-13 15:12

    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.

    0 讨论(0)
  • 2020-12-13 15:23

    You can think of it this way:

    • Action helpers are used to add methods to controllers.
    • Controller plugins are used to add routing / dispatch logic to controllers.

    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.

    0 讨论(0)
提交回复
热议问题