John Smitth
John Smitth

Reputation: 127

How to reach a GET parameter in configuration of form?

I'm in the middle of configure() method and I must set a default selected value for a combobox. The value is in the URL, but no request or any object.

How to reach this variable?

Upvotes: 0

Views: 691

Answers (2)

Vlad Jula-Nedelcu
Vlad Jula-Nedelcu

Reputation: 1696

Not a good idea to use sfContext in that context.

Better send the parameter in the constructor of the form. Something like this:

$form = new Form(array(), array(‘my_form_param’ => $request->getParameter('my_get_param'));

In the form you can call it with:

$this->getOption('my_form_param')

Upvotes: 4

John Carter
John Carter

Reputation: 55271

You can access the request from anywhere like this:

sfContext::getInstance()->getRequest()->getParameter('foo')

Upvotes: 1

Related Questions