How to get the request parameters in Symfony 2?
I do it even simpler:
use Symfony\Component\HttpFoundation\Request;public function updateAction(Request $request){ $foo = $request->get('foo'); $bar = $request->get('bar');}
Another option is to introduce your parameters into your action function definition:
use Symfony\Component\HttpFoundation\Request;public function updateAction(Request $request, $foo, $bar){ echo $foo; echo $bar;}
which, then assumes that you defined {foo} and {bar} as part of your URL pattern in your routing.yml file:
acme_myurl: pattern: /acme/news/{foo}/{bar} defaults: { _controller: AcmeBundle:Default:getnews }
You can Use The following code to get your form field values
use Symfony\Component\HttpFoundation\Request;public function updateAction(Request $request){ // retrieve GET and POST variables respectively $request->query->get('foo'); $request->request->get('bar', 'default value if bar does not exist');}
Or You can also get all the form values as array by using
$request->request->all()