Symfony2 通过 POST 从 URL 获取数组

标签 symfony

我通过 POST 发送一些数据。

例如:http://.../?tag[]=1&tag[]=2

我无法在 Controller 中接收标签变量,我尝试做这样的事情:

$this->get('request')->get('tag');

但我收到 null。

怎么了?

最佳答案

如果您通过 URL 发送数据,则这是一个 GET 请求。

public function exampleAction(Request $request)
{
    $tagPost=$request->request->get('tag');     //from $_POST[]
    $tagGet=$request->query->get('tag');        //from $_GET[]
    var_dump($tagPost,$tagGet);
}

关于Symfony2 通过 POST 从 URL 获取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975848/

相关文章:

Symfony2 + GitFlow + Capifony + Capistrano-ext

php - 移除删除复选框 Sonata Admin Bundle

symfony - Assetic 和我的 Assets

php - Doctrine DBAL 如果不存在则插入

php - MySQL 数据库尝试更新信息但未出现在网站上

Symfony2 更新 bootstrap.php.cache

php - 在 Doctrine 和 Symfony2 中使用自定义 DQL 函数时出错

php - Symfony 安全 : Is there an event when a user is authenticated from the session?

sockets - ClankBundle 不会触发订阅

symfony - 如何在 Symfony 4 中为测试环境设置数据库