Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get parameters from URL in Controller Symfony2

I try to submit my form by get method, but then in controller I cant get value, here is controller:

  var_dump($request->query->get('startPoint')); // its NULL

My form:

<form id="s_f" action ="{{ path('trip_search') }}" method="get" novalidate="">
    {{ form_widget(search_form, {'attr': {'class': 'search_form'} }) }}
</form>

Generated url:

http://example.com/app_dev.php/search_trips?search_form%5BstartPoint%5D=3123123&search_form%5BendPoint%5D=&search_form%5

Maybe problem related with this symbols %5D in the URL ? Can somebody help me?

like image 298
nowiko Avatar asked Dec 26 '22 01:12

nowiko


1 Answers

Do like this, if you can't find QS values:

var_dump($request->query->all());

it shows all QS values;

In your case, you can access your QS data by:

$formData = $request->query->get('search_form');

or

$formData = $request->query->get($form->getName());

it returns array of values, after that you can access startPoints like this:

$formData['startPoints']
like image 166
xurshid29 Avatar answered Dec 27 '22 20:12

xurshid29