[英]$_GET in symfony2 to get many variables
I'm trying to get the variables from a $_GET request the request is like /markers/var1/var2/var3/var4 the route file is as follows: 我正在尝试从$ _GET请求中获取变量,该请求就像/ markers / var1 / var2 / var3 / var4一样,路由文件如下:
Markers:
pattern: /markers/{slug}
defaults: { _controller: ngNearBundle:Markers:index }
First question is : 第一个问题是:
thanks ! 谢谢 !
1) 1)
Yes it needs to be an action inside of a controller. 是的,它必须是控制器内部的动作。 If you return a
JSON
body you can use the JsonResponse . 如果返回
JSON
正文,则可以使用JsonResponse 。
2) 2)
You just need to change the pattern of your action
您只需要更改
action
Markers:
pattern: /markers/{slug}/{var2}/{var3}/{var4}
defaults: { _controller: ngNearBundle:Markers:index }
And in your MarkersController
you add an action like this: 然后在您的
MarkersController
添加如下操作:
public function indexAction($slug, $var2, $var3, $var4) {
//...
}
Alternatively you can leave your route like this: /markers/{slug}
, add the other variables as plain GET
variables ( /markers/test?var2=a&var3=b&var4=c
) and access them in your action
like this: 或者,您可以这样离开路线:
/markers/{slug}
,将其他变量添加为纯GET
变量( /markers/test?var2=a&var3=b&var4=c
),然后按以下action
访问:
public function indexAction(Request $request, $slug) {
$var2 = $request->query->get('var2');
// and so on...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.