在 symfony 2 Controller 中,每次我想从帖子中获取值时,我都需要运行:
$this->getRequest()->get('value1');
$this->getRequest()->get('value2');
有没有办法将这些合并到一个返回数组的语句中? Zend 的 getParams() 之类的东西?
最佳答案
您可以执行 $this->getRequest()->query->all();
来获取所有 GET 参数和 $this->getRequest()->request-> all();
获取所有 POST 参数。
所以在你的情况下:
$params = $this->getRequest()->request->all();
$params['value1'];
$params['value2'];
有关 Request 类的更多信息,请参阅 http://api.symfony.com/2.8/Symfony/Component/HttpFoundation/Request.html
关于php - 在 Symfony 2 中获取所有请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11227285/