I have an upload form, which is displayed on overlay/lightbox/toplayer. It’s available only for several actions in several controllers.
Creating this form needs ~6 lines of code and needs access to REQUEST object to grab params from it.
Where should I put this code, so I could easily create my form in actions I need.
I’d put this functionality in an Action Helper. An action helper can be called directly from any controller action (and is lazy loaded) and action helpers have access to everything the controller action does including the request object and view.
Example:
Place that code in
library/My/Action/Helper/FormCreator.php(or where desired and change the class name).Then, in your actions, call it like this:
Lastly, we need to tell the helper broker where to find this action helper. To do so, add this to your bootstrap:
Hope that helps.