ZF-5518: Zend_View_Helper_Action tries to render wrong view script

Description

I have 3 modules in my project. Default, Forum and News. On my startpage (Which is IndexController and indexAction of the default module) in the view script file i have $this->action('list', 'index', 'news'), but it won't render the right list.phtml which is the one in my news module, it tries to render the list.phtml in my default module, but it don't have one so it returns an empty string. When i created list.phtml in my default module and put "hello" in it, then it will show the "Hello" string on my startpage.

Comments

Assigning to Ralph.

I modified the _script method of the Zend_View_Abstract class into the following code

/**
 * Finds a view script from the available directories.
 *
 * @param $name string The base name of the script.
 * @return void
 */
protected function _script($name)
{
    if (0 == count($this->_path['script'])) {
        require_once 'Zend/View/Exception.php';
        throw new Zend_View_Exception('no view script directory set; unable to determine location for view script',
            $this);
    }

    // If the Zend_View_Helper_Action is called, then look through the requested modules view scripts first.
    if (isset($this->_helper['Action']->request)) {
        $request = $request = $this->_helper['Action']->request;
        $actionModuleName = $request->getModuleName();
        if ($moduleScriptDirectories = preg_grep("/$moduleName/i", $this->_path['script'])) {
            foreach ($moduleScriptDirectories as $dir) {
                if (is_readable($dir . $name)) {
                    return $dir . $name;
                }
            }
        }
    }

    foreach ($this->_path['script'] as $dir) {
        if (is_readable($dir . $name)) {
            return $dir . $name;
        }
    }

    require_once 'Zend/View/Exception.php';
    $message = "script '$name' not found in path ("
             . implode(PATH_SEPARATOR, $this->_path['script'])
             . ")";
    throw new Zend_View_Exception($message, $this);
}

Maybe not the most elegant code, but it does the trick.

Ignore my previous post

This is the working method

{quote} /** * Finds a view script from the available directories. * * @param $name string The base name of the script. * @return void */ protected function _script($name) { if (0 == count($this->_path['script'])) { require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception('no view script directory set; unable to determine location for view script', $this); }

    // If the Zend_View_Helper_Action is called, then look through the requested modules view scripts first.
    if (isset($this->_helper['Action']->request)) {
        $request = $request = $this->_helper['Action']->request;
        $actionModuleName = $request->getModuleName();
        if ($moduleScriptDirectories = preg_grep("/$actionModuleName/i", $this->_path['script'])) {
            foreach ($moduleScriptDirectories as $dir) {
                if (is_readable($dir . $name)) {
                    return $dir . $name;
                }
            }
        }
    }

    foreach ($this->_path['script'] as $dir) {
        if (is_readable($dir . $name)) {
            return $dir . $name;
        }
    }

    require_once 'Zend/View/Exception.php';
    $message = "script '$name' not found in path ("
             . implode(PATH_SEPARATOR, $this->_path['script'])
             . ")";
    throw new Zend_View_Exception($message, $this);
}

{quote}

Calle,

Can you post a patch file instead of the updated code. This can be fixed faster that way.

Thanks.

Jon

Here is my patched Zend_View_Helper_Action

The former file i uploaded (Action.php) is wrong!

This is the correct patched file, im sorry for the wrong upload, im a bit tired at the moment.

Same error on 1.9.1. I never had to explicitly set the view directory up to 1.7.8.

Still trying to trace why this is the case. I'm using the modular structure.

You're aware that using the action view helper is generally considered bad practice? http://rmauger.co.uk/2009/03/…

This is my error messages. Unfortunately not related to the action helper. It doesn't look like it at least.


[13-Aug-2009 15:35:39] PHP Fatal error:  Uncaught exception 'Zend_View_Exception' with message 'no view script directory set; unable to determine location for view script' in /foo/library/Zend/View/Abstract.php:912
Stack trace:
#0 /foo/library/Zend/View/Abstract.php(829): Zend_View_Abstract->_script('error/error.pht...')
#1 /foo/library/Zend/Controller/Action/Helper/ViewRenderer.php(903): Zend_View_Abstract->render('error/error.pht...')
#2 /foo/library/Zend/Controller/Action/Helper/ViewRenderer.php(924): Zend_Controller_Action_Helper_ViewRenderer->renderScript('error$
#3 /foo/library/Zend/Controller/Action/Helper/ViewRenderer.php(963): Zend_Controller_Action_Helper_ViewRenderer->render()
#4 /foo/library/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#5 /foo/library/Zend/Controller/Action.php(523): Zen in /foo/library/Zend/View/Abstract.php on line 912

Ok, we switched to Zend_Layout.

I used {{addBasePath()}} on {{Zend_View}} and that seems to have effectively fix it for me. I'm not sure why I needed that all of a sudden.

Does that mean we can mark the issue as resolved now?

Looks like it can be worked around, but the problem is still there. Give it a week or two, I assigned it to myself after exchanging emails with Till, so I'll investigate more thoroughly over the weekend. There's also several patched files attached claiming to resolve this without needing a workaround or change in practice.

Till, can you explain more precisely what your resolution was for the record?

Any ideas or movement here?