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

Issue Type: Bug Created: 2009-04-02T22:06:15.000+0000 Last Updated: 2012-11-20T20:53:22.000+0000 Status: Closed Fix version(s): Reporter: Josiah Truasheim (josiah) Assignee: None Tags: - Zend_View

Related issues: Attachments:


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);


Posted by Josiah Truasheim (josiah) on 2009-04-02T22:07:34.000+0000

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.

Posted by Josiah Truasheim (josiah) on 2009-04-02T23:00:10.000+0000

// 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);

Posted by Rob Allen (rob) on 2012-11-20T20:53:22.000+0000

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.

Have you found an issue?

See the Overview section for more details.


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

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