View helper HeadScript

5 messages Options
Embed this post
Permalink
Ed Lazor-3

View helper HeadScript

Reply Threaded More More options
Print post
Permalink
Any idea why this isn't working from within a view helper that extends
Zend_View_Helper_Abstract?

                $this->view->HeadScript()->appendFile('/js/test.js', 'text/javascript');

It works if I move the line to the controller action.

-Ed
Duo Zheng

Re: View helper HeadScript

Reply Threaded More More options
Print post
Permalink
Ed,
View helpers shouldn't have an instance of $this->view no?  Shouldn't it be

$this->headScript()->appendFile('/js/test.js', 'text/javascript');

?

On Tue, Oct 13, 2009 at 6:44 PM, Ed Lazor <[hidden email]> wrote:
Any idea why this isn't working from within a view helper that extends
Zend_View_Helper_Abstract?

               $this->view->HeadScript()->appendFile('/js/test.js', 'text/javascript');

It works if I move the line to the controller action.

-Ed


Jurian Sluiman

Re: View helper HeadScript

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi all,
The view helper has a property $view so inside view helpers extending Zend_View_Helper_Abstract you should do $this->view->helper('something');


But Ed, I think you're having the problem because the view helper headScript() is used first and then you're adding some more files. It's something which isn't clear from your mail, but it might be the problem (I have dealt with that mistake many times ;) ).


Regards, Jurian


--
Jurian Sluiman
Soflomo.com


Op Wednesday 14 October 2009 05:42:20 schreef Duo Zheng:
> Ed,
> View helpers shouldn't have an instance of $this->view no? Shouldn't it be
>
> $this->headScript()->appendFile('/js/test.js', 'text/javascript');
>
> ?
>
> On Tue, Oct 13, 2009 at 6:44 PM, Ed Lazor <[hidden email]>wrote:
> > Any idea why this isn't working from within a view helper that extends
> > Zend_View_Helper_Abstract?
> >
> > $this->view->HeadScript()->appendFile('/js/test.js',
> > 'text/javascript');
> >
> > It works if I move the line to the controller action.
> >
> > -Ed



signature.asc (204 bytes) Download Attachment
Ed Lazor-3

Re: View helper HeadScript

Reply Threaded More More options
Print post
Permalink
Hi =)

> But Ed, I think you're having the problem because the view helper
> headScript() is used first and then you're adding some more files. It's
> something which isn't clear from your mail, but it might be the problem (I
> have dealt with that mistake many times ;) ).

Jurian, that's exactly what the problem was.  I was thinking of
switching to using a view action helper, but that might still have the
same timing issue.  How do you usually solve this problem?

-Ed
Jurian Sluiman

Re: View helper HeadScript

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Do you mean a view helper or an action helper? They are different things.


It is depending on what your use case is. You might solve the problem by using a placeholder. The view helper is instantiated before you actually display the output. But that might not be the best solution (and I think it's using the wrong tool for the job). You might be able to access the headScript helper and add the file inside your action controller or add the script during the rendering of the view for your controller action.


Regards, Jurian
--
Jurian Sluiman
Soflomo.com


Op Wednesday 14 October 2009 16:40:22 schreef Ed Lazor:
> Hi =)
>
> > But Ed, I think you're having the problem because the view helper
> > headScript() is used first and then you're adding some more files. It's
> > something which isn't clear from your mail, but it might be the problem
> > (I have dealt with that mistake many times ;) ).
>
> Jurian, that's exactly what the problem was. I was thinking of
> switching to using a view action helper, but that might still have the
> same timing issue. How do you usually solve this problem?
>
> -Ed



signature.asc (204 bytes) Download Attachment