Problem with view helper paths

View: New views
3 Messages — Rating Filter:   Alert me  

Problem with view helper paths

by Janimatti Ellonen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!


$path = $this->getHelperPaths();
print_r($paths);

prints:


    Array
(
    [Zend_View_Helper_] => Array
        (
            [0] => Zend/View/Helper/
            [1] => /usr/local/apache2/htdocs/xxxx/application/views/helpers/
            [2] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/mildola/
            [3] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/template/
            [4] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/roles/
            [5] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/categories/
            [6] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/languages/
            [7] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/versions/
            [8] =>
/usr/local/apache2/htdocs/xxxx/application/views/helpers/processindicator/
        )

    [Image_View_Helper_] => Array
        (
            [0] =>
/usr/local/apache2/htdocs/xxxx/application/module/image/views/helpers/
        )

)


Now when I try to use $this->language(); // helper resides in
/usr/local/apache2/htdocs/xxxx/application/views/helpers/

I get:

'Exception' with message
'fopen(/usr/local/apache2/htdocs/xxx/application/module/image/views/helpers/Language.php)
[<a href='function.fopen'>function.fopen</a>]: failed to open stream: No
such file or directory'

I assumed that zf would search through all set paths before complaining.
Now it seems to just the last path, which is set automatically as I have
not set it myself anywhere.

Re: Problem with view helper paths

by Janimatti Ellonen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Janimatti Ellonen kirjoitti:

> Hi!
>
>
> $path = $this->getHelperPaths();
> print_r($paths);
>
> prints:
>
>
>    Array
> (
>    [Zend_View_Helper_] => Array
>        (
>            [0] => Zend/View/Helper/
>            [1] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/
>            [2] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/mildola/
>            [3] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/template/
>            [4] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/roles/
>            [5] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/categories/
>            [6] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/languages/
>            [7] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/versions/
>            [8] =>
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/processindicator/
>
>        )
>
>    [Image_View_Helper_] => Array
>        (
>            [0] =>
> /usr/local/apache2/htdocs/xxxx/application/module/image/views/helpers/
>        )
>
> )
>
>
> Now when I try to use $this->language(); // helper resides in
> /usr/local/apache2/htdocs/xxxx/application/views/helpers/
>
> I get:
>
> 'Exception' with message
> 'fopen(/usr/local/apache2/htdocs/xxx/application/module/image/views/helpers/Language.php)
> [<a href='function.fopen'>function.fopen</a>]: failed to open stream:
> No such file or directory'
>
> I assumed that zf would search through all set paths before
> complaining. Now it seems to just the last path, which is set
> automatically as I have not set it myself anywhere.
>


The following piece of code seems to solve the problem. Actually I used
the same code when I hade the same problem with 1.5.0PR.

Current version of method in Zend_Loader (1.5.2) which makes my app go
bonkers:

    public static function isReadable($filename)
    {
        if (!$fh = @fopen($filename, 'r', true)) {
            return false;
        }

        return true;
    }

My version, which keeps my app happy:

    public static function isReadable($filename)
    {
        if (@is_readable($filename)) {
            return true;
        }

        $path = get_include_path();
        $dirs = explode(PATH_SEPARATOR, $path);

        foreach ($dirs as $dir) {
            if ('.' == $dir || '..' == $dir) {
                continue;
            }

            if (@is_readable($dir . DIRECTORY_SEPARATOR . $filename)) {
                return true;
            }
        }

        return false;
    }

- - -

Janimatti Ellonen

Re: Re: Problem with view helper paths

by Matthew Weier O'Phinney-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-- Janimatti Ellonen <janimatti.ellonen@...> wrote
(on Saturday, 19 July 2008, 09:04 PM +0300):
> Janimatti Ellonen kirjoitti:

<snip>

> > Now when I try to use $this-> language(); // helper resides in  
> > /usr/local/apache2/htdocs/xxxx/application/views/helpers/
> >
> > I get:
> >
> > 'Exception' with message  
> > 'fopen(/usr/local/apache2/htdocs/xxx/application/module/image/views/helpers/Language.php)
> > [<a href='function.fopen'> function.fopen</a> ]: failed to open stream:  
> > No such file or directory'
> >
> > I assumed that zf would search through all set paths before  
> > complaining. Now it seems to just the last path, which is set  
> > automatically as I have not set it myself anywhere.
>
>
> The following piece of code seems to solve the problem. Actually I used  
> the same code when I hade the same problem with 1.5.0PR.
>
> Current version of method in Zend_Loader (1.5.2) which makes my app go  
> bonkers:
>
>    public static function isReadable($filename)
>    {
>        if (!$fh = @fopen($filename, 'r', true)) {
>            return false;
>        }
>
>        return true;
>    }
>
> My version, which keeps my app happy:
>
>    public static function isReadable($filename)
>    {
>        if (@is_readable($filename)) {
>            return true;
>        }

This tells me that one or both of you are using an error_handler that's
being a little too strict and throwing exceptions on warnings. I'd
recommend if you are that you filter out fopen errors.

The changes you have made to Zend_Loader are terribly, terribly
non-performant, and performance will degrade exponentially the more
paths you have on your include_path -- I know, because we switched back
to using the fopen() hack from code that looked like this.

>
>        $path = get_include_path();
>        $dirs = explode(PATH_SEPARATOR, $path);
>
>        foreach ($dirs as $dir) {
>            if ('.' == $dir || '..' == $dir) {
>                continue;
>            }
>
>            if (@is_readable($dir . DIRECTORY_SEPARATOR . $filename)) {
>                return true;
>            }
>        }
>
>        return false;
>    }

--
Matthew Weier O'Phinney
Software Architect       | matthew@...
Zend Framework           | http://framework.zend.com/
LightInTheBox - Buy quality products at wholesale price