2010年2月21日星期日

Re: [fw-mvc] Re: How to extend Zend_View?

Hi,

this is very wrong way to do it as you basically making your app to create new instances of My_View every single time that method is called. This is not what you need.

You better create your own view resource:

<?php

class App_Application_Resource_View extends Zend_Application_Resource_View
{
    /**
     * Get view
     *
     * @return App_View
     */
    public function getView() {

        if (null === $this->_view) {
            $this->_view = new App_View($this->getOptions());
        }
        return $this->_view;
    }
}

That's it - all configuration is still the same, but you are using custom class now, plus no hacks are required.

--
Juozas Kaziukėnas (juozas@juokaz.com)
Aš internete - JuoKaz (http://www.juokaz.com)


On Sun, Feb 21, 2010 at 8:13 PM, electrotype <electrotype@gmail.com> wrote:

In fact, instead of removing "resources.view[] =", since some view
configurations may be needed sometimes I guess, I override _bootstrap() in
my bootstrap, to be able to set my own view after the ressources are loaded:

------------------------

   protected function _bootstrap($resource = null)
   {
       parent::_bootstrap($resource);

       $viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
       $view = new My_View();
       $viewRenderer->setView($view);
   }

------------------------

This works great...
--
View this message in context: http://n4.nabble.com/How-to-extend-Zend-View-tp1563653p1563765.html
Sent from the Zend MVC mailing list archive at Nabble.com.


没有评论: