0
votes

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!

1

1 Answers

1
votes

You could do it with an ActionHelper. But you would have to call it explicitly then. The preDispatch callback 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_Locale in your bootstrap, before initializing Zend_View. You could then fetch the locale when initializing Zend_View and adjust paths directly during bootstrap, instead of during the dispatch cycle. See the examples on Zend_Application for an idea.