phpsymfonyparametersgettwig

How to generate url in twig passing parameters?


Maybe this is a stupid question but I spent a lot of time trying to make it working...

This is from my routing file:

search:
  path: /search
  defaults: { _controller: MyAppBundle:Default:search}

My twig template:

{{ path('search', {'value': value}) }}

And my controller:

public function searchAction(Request $request){
        $value = $request->query->get('value');

My problem is the following, with the above data I am generating this url:

/search/value

instead of the url which I want:

/search?value=value

I prefer clean urls, but I need to pass the values in the url using "?" due to that I need to pass different values in the url and some of them can be omitted in different circumstances


Solution

  • If you face this issue, please check that you aren't passing your parameters in your routing file and also check that you haven't a form in your html with post as method (if you have any form with post method, changing it to get will solve the issue)