0

Hello I'm trying to send multiple parameters from twig like this

<a href={{path('myRoute',{'param1':param1,'param2':param2})}}>Link</a>

I have declare my controller as follows:

 /**
     * @Route("/categoria/{param1}", name="categoria")
     */
public function taskAction($param1){

}

But how can I send the second parameter and not including it in the route, so far what happens is that I get a rout like this

/categoria/param1?param2=1

and i expect a route like

/categoria/param1

and be able to access the second parameter but I don't want the second parameter appears in the route.

j08691
  • 204,283
  • 31
  • 260
  • 272
Álvaro
  • 157
  • 4
  • 10
  • 2
    you can't pass a get param without seeing it in the url ... – t-n-y Aug 22 '17 at 16:09
  • ok, thanks @t-n-y i think i have to include it in the route or look for other option right? – Álvaro Aug 22 '17 at 16:20
  • it depends of your needs, i don't know what is this param. but you can pass it in the route or for exemple pass it in session ... it depends of your needs – t-n-y Aug 22 '17 at 16:25
  • 1
    all the params not defined in the route are accessible as query string parameters, as example `$request->get('param2');` – Matteo Aug 22 '17 at 16:29
  • yes, my params are for example param1 = tools, param2 = 1 where param1 is my category name and param2 and id, so i just want a route when i can only show category name as /category/tools and not something like /categoriy/1/tools @t-n-y – Álvaro Aug 22 '17 at 16:31
  • thanks @Matteo but what happens is that the param not included in the route appears as this /route/param1?param2=1 with the sintaxis using interrogation and equal signs – Álvaro Aug 22 '17 at 16:33
  • Please let us know what you are expecting – Nandakumar Aug 22 '17 at 17:36

3 Answers3

0

I don't understand exactly what do you want but a possible solution would be:

Send an ajax request when you press the link with the parameters you want. Then in your controller you will have something like this

public function taskAction(Request $request){

}

Finally return a response to your view

Maybe giving some info about the functionality you want to achieve would help us understand

l.g.karolos
  • 1,131
  • 1
  • 10
  • 25
0

Try this

/**
* 
* @Route("/category/{id}", name="category_delete")
*/    
public function myAction(Request $request, Category $category)
{
     $param1 = $request->get('param1');
     $param2 = $request->get('param2');
         .
         .
     $paramN = $request->get('paramN');
}
Farshadi
  • 143
  • 1
  • 12
0

You have to pass the first param as part of the route as you already did and you have to send a POST request when user clicks the link (using javascript) in order to send other params via post. Check this as an example: https://gist.github.com/hellomedia/048906b9449463cd5792

or you can implement a similar logic as you wish.

meteorite
  • 736
  • 1
  • 8
  • 17