2
votes

I am new to Zend Framework. 1st things 1st, I want to change that .phtml extention to .php in the views.

After researching, I found that this code works, in the init method of different controllers:

$this->getHelper('viewRenderer')->setViewSuffix('php');

Problem is that I have to repeat that code in every controller, which is something bad and defeats the purpose of using a framework.

I could have subclassed the Zend_Controller_Action into some base controller with all the shared code which all other controllers can inherit from, but as far as I know, it's not the best practice to do.

How can I achieve the shared code without subclassing the Zend_Controller_Action class and without using any plugins or Action helpers

Thanks in advance.

1
I would recommend the base controller method. This base controller could also be used to hook in your login scripts and other pre render logic.JohnP

1 Answers

1
votes

Just figured it out..No need for any base controllers.

In the bootstap, I wrote this code:

protected function _initViewSuffix() {

$this->bootstrap('View');
    $view = $this->getResource('View');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$viewRenderer->setViewSuffix('php');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}

And then in Application.ini, I added this line:

resources.view = []

Now it works.