url helper available all over your app

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

url helper available all over your app

umpirsky
Hi.

I wonder, if you want to use url helper for all urls in your app, you can access it from view with $this->url(). from controller with $this->wiew->url()...

But when you want for example to use it to set action of a form in form init() method, do you access it through front controller or bootstrap or you set action explicitly in the view script?
What is the right way to go?

Regards,
Sasa Stamenkovic.
Reply | Threaded
Open this post in threaded view
|

Re: url helper available all over your app

SpiffyJr

umpirsky wrote
Hi.

I wonder, if you want to use url helper for all urls in your app, you can access it from view with $this->url(). from controller with $this->wiew->url()...

But when you want for example to use it to set action of a form in form init() method, do you access it through front controller or bootstrap or you set action explicitly in the view script?
What is the right way to go?

Regards,
Sasa Stamenkovic.
You can do that easily using the form view helper and the URL of the calling page so doing so from the init() method isn't required. For example,

indexAction()
{
  $this->view->form = new Default_Form_MyForm();
}


index.phtml
<?=$this->form->setAction($this->url());?>

You could probably do it in the form using the helper broker but I've never had a need to do so.
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: url helper available all over your app

umpirsky
Why I want to do this in the form is, I want to set url on one place. Form will be rendered in many views, I don't want each of them set separate url, want to do it in one place, in the form init.

Regards,
Saša Stamenković


On Wed, Oct 21, 2009 at 3:22 PM, Kyle Spraggs <[hidden email]> wrote:



umpirsky wrote:
>
> Hi.
>
> I wonder, if you want to use url helper for all urls in your app, you can
> access it from view with $this->url(). from controller with
> $this->wiew->url()...
>
> But when you want for example to use it to set action of a form in form
> init() method, do you access it through front controller or bootstrap or
> you set action explicitly in the view script?
> What is the right way to go?
>
> Regards,
> Sasa Stamenkovic.
>

You can do that easily using the form view helper and the URL of the calling
page so doing so from the init() method isn't required. For example,

indexAction()
{
 $this->view->form = new Default_Form_MyForm();
}


index.phtml
<?=$this->form->setAction($this->url());?>

You could probably do it in the form using the helper broker but I've never
had a need to do so.
--
View this message in context: http://www.nabble.com/url-helper-available-all-over-your-app-tp25992262p25992433.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: url helper available all over your app

Jurian Sluiman-4
If you use the form at multiple places, you could consider making it into a view helper. The helper is easy to place inside your views and inside the helper you could initialize the form and set its action url.
Regards, Jurian
--
Jurian Sluiman
Soflomo.com


Op Wednesday 21 October 2009 15:47:45 schreef Саша Стаменковић:
> Why I want to do this in the form is, I want to set url on one place. Form
> will be rendered in many views, I don't want each of them set separate url,
> want to do it in one place, in the form init.
>
> Regards,
> Saša Stamenković
>
> On Wed, Oct 21, 2009 at 3:22 PM, Kyle Spraggs <[hidden email]> wrote:
> > umpirsky wrote:
> > > Hi.
> > >
> > > I wonder, if you want to use url helper for all urls in your app, you
> > > can access it from view with $this->url(). from controller with
> > > $this->wiew->url()...
> > >
> > > But when you want for example to use it to set action of a form in form
> > > init() method, do you access it through front controller or bootstrap
> > > or you set action explicitly in the view script?
> > > What is the right way to go?
> > >
> > > Regards,
> > > Sasa Stamenkovic.
> >
> > You can do that easily using the form view helper and the URL of the
> > calling
> > page so doing so from the init() method isn't required. For example,
> >
> > indexAction()
> > {
> > $this->view->form = new Default_Form_MyForm();
> > }
> >
> >
> > index.phtml
> > <?=$this->form->setAction($this->url());?>
> >
> > You could probably do it in the form using the helper broker but I've
> > never had a need to do so.
> > --
> > View this message in context:
> > http://www.nabble.com/url-helper-available-all-over-your-app-tp25992262p2
> >5992433.html Sent from the Zend Framework mailing list archive at
> > Nabble.com.


signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: url helper available all over your app

Hector Virgen
In reply to this post by umpirsky
Forms have access to a view object, which it pulls automatically from the ViewRenderer action helper.

class MyForm extends Zend_Form
{
    public function init()
    {
        $action = $this->getView()->url(/* ... */);
        $this->setAction($action);
        /* ... */
    }
}

--
Hector


On Wed, Oct 21, 2009 at 6:47 AM, Саша Стаменковић <[hidden email]> wrote:
Why I want to do this in the form is, I want to set url on one place. Form will be rendered in many views, I don't want each of them set separate url, want to do it in one place, in the form init.

Regards,
Saša Stamenković



On Wed, Oct 21, 2009 at 3:22 PM, Kyle Spraggs <[hidden email]> wrote:



umpirsky wrote:
>
> Hi.
>
> I wonder, if you want to use url helper for all urls in your app, you can
> access it from view with $this->url(). from controller with
> $this->wiew->url()...
>
> But when you want for example to use it to set action of a form in form
> init() method, do you access it through front controller or bootstrap or
> you set action explicitly in the view script?
> What is the right way to go?
>
> Regards,
> Sasa Stamenkovic.
>

You can do that easily using the form view helper and the URL of the calling
page so doing so from the init() method isn't required. For example,

indexAction()
{
 $this->view->form = new Default_Form_MyForm();
}


index.phtml
<?=$this->form->setAction($this->url());?>

You could probably do it in the form using the helper broker but I've never
had a need to do so.
--
View this message in context: http://www.nabble.com/url-helper-available-all-over-your-app-tp25992262p25992433.html
Sent from the Zend Framework mailing list archive at Nabble.com.



--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: url helper available all over your app

umpirsky
In reply to this post by Jurian Sluiman-4
Thanks guys, that was really helpful!

Regards,
Saša Stamenković


On Wed, Oct 21, 2009 at 5:59 PM, Jurian Sluiman <[hidden email]> wrote:
If you use the form at multiple places, you could consider making it into a view helper. The helper is easy to place inside your views and inside the helper you could initialize the form and set its action url.
Regards, Jurian
--
Jurian Sluiman
Soflomo.com


Op Wednesday 21 October 2009 15:47:45 schreef Саша Стаменковић:

> Why I want to do this in the form is, I want to set url on one place. Form
> will be rendered in many views, I don't want each of them set separate url,
> want to do it in one place, in the form init.
>
> Regards,
> Saša Stamenković
>
> On Wed, Oct 21, 2009 at 3:22 PM, Kyle Spraggs <[hidden email]> wrote:
> > umpirsky wrote:
> > > Hi.
> > >
> > > I wonder, if you want to use url helper for all urls in your app, you
> > > can access it from view with $this->url(). from controller with
> > > $this->wiew->url()...
> > >
> > > But when you want for example to use it to set action of a form in form
> > > init() method, do you access it through front controller or bootstrap
> > > or you set action explicitly in the view script?
> > > What is the right way to go?
> > >
> > > Regards,
> > > Sasa Stamenkovic.
> >
> > You can do that easily using the form view helper and the URL of the
> > calling
> > page so doing so from the init() method isn't required. For example,
> >
> > indexAction()
> > {
> > $this->view->form = new Default_Form_MyForm();
> > }
> >
> >
> > index.phtml
> > <?=$this->form->setAction($this->url());?>
> >
> > You could probably do it in the form using the helper broker but I've
> > never had a need to do so.
> > --
> > View this message in context:
> > http://www.nabble.com/url-helper-available-all-over-your-app-tp25992262p2
> >5992433.html Sent from the Zend Framework mailing list archive at
> > Nabble.com.