views:

103

answers:

1

Hi,

The standard extension for template files in Zend Framework is .phtml... I need to change them to .js in one specific module... can anyone help... I'd ideally like to change this a Controller level...

Many thanks...

+3  A: 

In your controller:

public function init() {
    $this->getHelper('viewRenderer')->setViewSuffix('js');
}

If you need to apply this to all controllers within a module, you should place this in an abstract controller class used for that module and have each controller in that module inherit from that abstract class.

You could theoretically put this in the module's bootstrap, but it would set the view suffix to 'js' for every request, even ones that end up not being routed to that specific module. This is because every module's bootstrap is executed for each request, regardless of which module is selected by the dispatcher.

The controller's init() function, though, will only execute when the module is selected for dispatch.

awgy
in every controller in that module? no way to do it once?
takpar
I added a blurb to my answer about how to approach adding it to each controller. Hope that helps.
awgy
To do something at the module level, I typically use a frontcontroller plugin (http://devzone.zend.com/article/3372) with a routeShutdown() method. Good examples of these are layout switchers (like http://www.atirjavid.com/web-development/8-zend-framework-tutorials/4-a-modular-directory-structure-quickstart-module-switcher-front-controller-plugin.html).
David Weinraub