ZF-6201: Zend_View_Helper_Partial does not use the inflector when including cross module.


When using the partial view renderer with a module, it does not preserve the view renderer's base path spec (setViewBasePathSpec()) and instead reverts to the controller directory.


// Within the boot script $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' ); $viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );

// Within the view $this->partial( 'my/view.phtml', 'somemodule', array( 'foo' => 'bar' ) ); // Tries to look within the controller directory

// This is caused by these lines of codes within Zend/View/Helper/Partial.php (lines 75:82 inclusive) require_once 'Zend/Controller/Front.php'; $moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module); if (null === $moduleDir) { require_once 'Zend/View/Helper/Partial/Exception.php'; throw new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist'); } $viewsDir = dirname($moduleDir) . '/views'; $view->addBasePath($viewsDir);


I am working on a patch for this issue for my local copy of the zend framework (v1.7.8) I will post the source code when complete.

// To fix this issue replace Zend/View/Helper/Partial.php (lines 75:82 inclusive) with the following require_once 'Zend/Controller/Action/HelperBroker.php'; $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' ); // Load the inflector from the view renderer. $inflector = clone $viewRenderer->getInflector(); $basePathSpec = $viewRenderer->getViewBasePathSpec(); // Set the target of the inflector so that it does not affect the // view renderer. $inflector->setTarget( $basePathSpec ); // Set the path parts from the current request and dispatcher $request = $viewRenderer->getRequest(); $dispatcher = $viewRenderer->getFrontController()->getDispatcher(); $parts = array( 'module' => $module, 'controller' => $request->getControllerName(), 'action' => $dispatcher->formatActionName($request->getActionName()) ); // Filter the path using the inflector $path = $inflector->filter($parts); // Add the base path to the view // -- Isn't this practice inherintly dangerious because views could // be inadvertantly used from the new module path? // Would it not be better to create a new renderPath() method in // the view that renders an absolute path using the view? $view->addBasePath($path);

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.