Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all request parameters in Symfony 2

In symfony 2 controllers, every time I want to get a value from post I need to run:

$this->getRequest()->get('value1'); $this->getRequest()->get('value2'); 

Is there any way to consolidate these into one statement that would return an array? Something like Zend's getParams()?

like image 458
ContextSwitch Avatar asked Jun 27 '12 13:06

ContextSwitch


1 Answers

You can do $this->getRequest()->query->all(); to get all GET params and $this->getRequest()->request->all(); to get all POST params.

So in your case:

$params = $this->getRequest()->request->all(); $params['value1']; $params['value2']; 

For more info about the Request class, see http://api.symfony.com/2.8/Symfony/Component/HttpFoundation/Request.html

like image 170
Guillaume Flandre Avatar answered Oct 06 '22 00:10

Guillaume Flandre