php - 在 Symfony 2 中获取所有请求参数

标签 php symfony request

在 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/

相关文章:

javascript - 统计点击按钮创建 "Top Event"区域的次数

php - 扩展 Symfony 以自动转义 .tex.twig 文件的 latex 字符

testing - Symfony 功能测试 : receive uploaded file

php - 两个相关的下拉列表和文本区域(4 个文本区域)取决于 mysql 的最后一个下拉列表

php - MySQL根据另一个表的时间戳选择信息

php - 做一个jQuery $.post() 到一个PHP Controller,然后在中间返回到View,然后使用$.get() 继续Controller

php - Symfony 服务析构函数被多次调用

Node.js 请求对象文档?

javascript - 如何在 node.js 中的一定持续时间后强制解决 promise ?

javascript - 如何使用带有多个url的request-promise.js调用HTTP请求?