1

I'm trying to get the variables from a $_GET request the request is like /markers/var1/var2/var3/var4 the route file is as follows:

Markers:
pattern:  /markers/{slug}
defaults: { _controller: ngNearBundle:Markers:index }

First question is :

  1. does index method need to be an action method ? "indexAction" the method will output json.
  2. how can I get the value of var1 and var2 etc ... ?

thanks !

Aysennoussi
  • 3,720
  • 3
  • 36
  • 60

1 Answers1

2

1)
Yes it needs to be an action inside of a controller. If you return a JSON body you can use the JsonResponse.

2)
You just need to change the pattern of your action

Markers:
    pattern: /markers/{slug}/{var2}/{var3}/{var4}
    defaults: { _controller: ngNearBundle:Markers:index }

And in your MarkersController you add an action like this:

public function indexAction($slug, $var2, $var3, $var4) {
    //...
}

Alternatively you can leave your route like this: /markers/{slug}, add the other variables as plain GET variables (/markers/test?var2=a&var3=b&var4=c) and access them in your action like this:

public function indexAction(Request $request, $slug) {
    $var2 = $request->query->get('var2');
    // and so on...
}
ferdynator
  • 6,245
  • 3
  • 27
  • 56
  • Thanks a lot ! for Json I found this topic , not the top answer but the second one is great ! http://stackoverflow.com/questions/9146460/symfony2-echoing-json-from-a-controller-for-use-in-an-extjs-4-grid – Aysennoussi Jan 01 '14 at 16:32