Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework: Controller Plugins vs Action Helpers

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?

like image 843
Laimoncijus Avatar asked Mar 17 '10 15:03

Laimoncijus


2 Answers

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.

like image 154
Ballsacian1 Avatar answered Oct 23 '22 06:10

Ballsacian1


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.

like image 33
smack0007 Avatar answered Oct 23 '22 04:10

smack0007