Issues

ZF-1130: view suffix overridden when extending Zend_Controller_Action :: initView

Description

When overriding Zend_Controller_Action :: initView the viewSuffix will be overriden if you change it within the initView method.

Take the following code:


<?php

require_once 'Zend/Controller/Action.php';

class Sanmax_Controller_Action extends Zend_Controller_Action
{
    public function initView() 
    {
        if (null !== $this->view) {
            return; 
        }

        require_once 'Sanmax/View/Smarty.php';
        $config = Zend_Registry::get('config');

        $this->view = new Sanmax_View_Smarty($config->smarty->asArray());
        $this->viewSuffix = 'html';
                
        return $this->view;
    } 
}

Zend_Controller_Action will request the viewSuffix before it calls initView, and thus the viewSuffix will be reset to 'phtml'

Comments

This patch simply changes to variables from place, and fixes the issue. Please consider it.

Assigning to [~matthew].

Patch applied in revision 4307.

One note: Since $viewSuffix is a public property, this could have been achieved by simply setting the class property:


class My_Controller_Action extends Zend_Controller_Action
{
    public $viewSuffix = 'tpl';
}

instead of overriding it in initView().

Matthew Weier O'Phinney wrote:

"One note: Since $viewSuffix is a public property, this could have been achieved by simply setting the class property"

For anyone, like me, that ran across this while looking for a solution to their "controller action ignores custom viewSuffix" problem, Matthew's comment is unfortunately untrue. See ZF-5301.