ZF-9245: Set the view class in options for Zend_Application_Resource_View

Description

I have ran into a situation where I need to use a custom view. I quickly realized that the View resource explicitly calls Zend_View object which doesn't allow me an easy to way to set the "default view" of my app to my custom view.

There should be a simple option to pass in your custom class name for the view:


resources.view.className = "My_Custom_View_Class"

<?php
class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    // ... 

    public function getView()
    {
        if (null === $this->_view) {
            $options = $this->getOptions();

            $className = 'Zend_View';
            if (isset($options['className'])) {
                $className = $options['className'];
            }
            $this->_view = new $className($options);

            if(isset($options['doctype'])) {
                $this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
            }
        }
        return $this->_view;
    }
}

Comments

Patch for Zend/Application/Resource/View.php

Just ran into the same problem with ZF 1.11.11. Feels pretty bad to copypaste the entire Zend_Application_Resource_View::getView() method just for replacing Zend_View with my own view class.