Issues

ZF-5518: Zend_View_Helper_Action tries to render wrong view script

Issue Type: Bug Created: 2009-01-11T09:08:14.000+0000 Last Updated: 2011-08-14T19:00:06.000+0000 Status: Open Fix version(s): Reporter: Carl Broberg Gunnarsson (psil) Assignee: Pádraic Brady (padraic) Tags: - Zend_View

  • View_Helper
  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments: - Abstract.php

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

Posted by Matthew Weier O'Phinney (matthew) on 2009-01-11T09:50:05.000+0000

Assigning to Ralph.

Posted by Carl Broberg Gunnarsson (psil) on 2009-01-16T00:48:20.000+0000

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.

Posted by Carl Broberg Gunnarsson (psil) on 2009-01-16T01:12:46.000+0000

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}

Posted by Jon Whitcraft (sidhighwind) on 2009-02-06T13:01:22.000+0000

Calle,

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

Thanks.

Jon

Posted by Carl Broberg Gunnarsson (psil) on 2009-02-06T17:18:42.000+0000

Here is my patched Zend_View_Helper_Action

Posted by Carl Broberg Gunnarsson (psil) on 2009-02-06T17:26:02.000+0000

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.

Posted by Till Klampaeckel (till) on 2009-08-13T08:27:29.000+0000

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.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-08-13T08:52:08.000+0000

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

Posted by Till Klampaeckel (till) on 2009-08-13T10:13:17.000+0000

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

<pre class="highlight">
[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

Posted by Till Klampaeckel (till) on 2010-03-19T11:14:26.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2010-03-19T11:43:07.000+0000

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

Posted by Pádraic Brady (padraic) on 2010-03-19T11:59:26.000+0000

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?

Posted by Ralph Schindler (ralph) on 2011-02-18T15:14:24.000+0000

Any ideas or movement here?

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts