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

Issue Type: Improvement Created: 2007-03-24T12:59:15.000+0000 Last Updated: 2010-02-11T12:25:33.000+0000 Status: Resolved Fix version(s): - 0.9.2 (06/Apr/07)

Reporter: Andries Seutens (andries) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments: - Action.php.patch


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

Take the following code:

<pre class="highlight">

require_once 'Zend/Controller/Action.php';

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

        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'


Posted by Andries Seutens (andries) on 2007-03-24T12:59:55.000+0000

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

Posted by Darby Felton (darby) on 2007-03-28T09:38:36.000+0000

Assigning to [~matthew].

Posted by Matthew Weier O'Phinney (matthew) on 2007-04-02T11:38:07.000+0000

Patch applied in revision 4307.

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

<pre class="highlight">
class My_Controller_Action extends Zend_Controller_Action
    public $viewSuffix = 'tpl';

instead of overriding it in initView().

Posted by Ryan Lange (ryan.lange) on 2010-02-11T12:25:33.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.