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()?
Advertisement
Answer
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