I want to modify a view from Action Helper in Zend Framework in preDispatch() method.
So I do something like:
class MyHelper extends Zend_Controller_Action_Helper_Abstract {
public function preDispatch() {
$view = $this->getActionController()->view;
$view->doSomething();
}
}
Is it OK to do so? What I want to do is – MyHelper needs to adjust some paths to templates (in this case view is a SmartyView) according to users locale, so I would like to read out users locale in my action helper and then adjust view accordingly.
I am doing right here or should I go some different way?
Thanks!
You could do it with an ActionHelper. But you would have to call it explicitly then. The
preDispatchcallback method does not exist in an Action Helper. If you want to use the dispatch callbacks, you are looking for a Zend Controller Plugin.An alternative to your approach would be to init
Zend_Localein your bootstrap, before initializingZend_View. You could then fetch the locale when initializingZend_Viewand adjust paths directly during bootstrap, instead of during the dispatch cycle. See the examples onZend_Applicationfor an idea.