简体   繁体   English

如何在symfony2中获取多值get参数的值

[英]How to get value for multivalued get parameter in symfony2

How do you get the value for a get parameter that is a list of values? 如何获取作为值列表的get参数的值? I tried using request->query->get('parameter') but this only returns one value. 我尝试使用request->query->get('parameter')但这仅返回一个值。

Suppose you have a country parameter and want to pass more than 1 value. 假设您有一个国家/地区参数,并且想要传递多个值。 eg ... ?country=us,gb using get gives you 'us' only. 例如... ?country=us,gb使用get只会给您'us'。

I can not find this in the docs. 我在文档中找不到这个。

您必须以这种方式格式化查询参数

country[]=us&country[]=gb

From their manual (http://symfony.com/doc/current/book/http_fundamentals.html) 从他们的手册中(http://symfony.com/doc/current/book/http_fundamentals.html)

use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();

$request->query->get('foo');

Edit: 编辑:

Sorry, I misunderstood your question. 抱歉,我误解了你的问题。 You want an array of all GET valiables like $_GET will give you? 您想要像$ _GET这样的所有GET变量数组吗?

That can be done with (will also include POST parameters): 可以通过以下方式完成(还将包括POST参数):

 <?php $request->getParameterHolder()->getAll();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM