Matthew Weier O'Phinney a écrit :
-- Apsy <[EMAIL PROTECTED]> wrote
(on Friday, 12 September 2008, 01:04 PM +0200):
I have a problem with my custom class of Zend_View.

In my bootstrap, i have instanciate a plugin wich initialize the application like the "Pastebin" app of Matthew.
But i have a problem :
in my initView method of my plugin :

public function initView()
   {
       /*************************
        * View
        ************************/
       $view = new App_View_Page();

<snip: view configuration>

             /*************************
        * ViewRenderer
        ************************/
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
       $viewRenderer
            ->setViewBasePathSpec(BASE_PATH . '/application/design/views')
            ->setViewScriptPathSpec(':module/:controller/:action.:suffix')
            ->setViewSuffix('phtml');
       Zend_Debug::dump(get_class($viewRenderer->view));
       $viewRenderer->init();

Here's the problem, right there. init() will initialize a DIFFERENT view
object. What you want to do is add your already initialized view object
to the view renderer:

    $viewRenderer->setView($view);

and then things should work as expected

I've done it but it don't work...
It don't take care of the "->setViewScriptPathSpec(':module/:controller/:action.:suffix')". The View Renderer object i have seems to be a new one !

I think it's due to the dispatch method of the Zend_controller_Front where it instanciate a Zend_Controller_Action_Helper_ViewRenderer() at place -80 in the stack. isn't it ?

public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
  {
if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
          // Register with stack index of 100
          require_once 'Zend/Controller/Plugin/ErrorHandler.php';
$this->_plugins->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
      }

if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
          require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new Zend_Controller_Action_Helper_ViewRenderer());
      }

Reply via email to