在Symfony 2中获取所有请求参数 [英] Getting all request parameters in Symfony 2
问题描述
在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');
是否有任何方法可以将它们合并为一个将返回数组的语句?就像Zend的getParams()一样?
Is there any way to consolidate these into one statement that would return an array? Something like Zend's getParams()?
推荐答案
您可以执行$this->getRequest()->query->all();
获取所有GET参数,并执行$this->getRequest()->request->all();
获取所有POST参数.
You can do $this->getRequest()->query->all();
to get all GET params and $this->getRequest()->request->all();
to get all POST params.
所以在您的情况下:
$params = $this->getRequest()->request->all();
$params['value1'];
$params['value2'];
有关Request类的更多信息,请参见 http://api .symfony.com/2.8/Symfony/Component/HttpFoundation/Request.html
For more info about the Request class, see http://api.symfony.com/2.8/Symfony/Component/HttpFoundation/Request.html
这篇关于在Symfony 2中获取所有请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!