【发布时间】:2015-11-29 11:32:36
【问题描述】:
在 Symfony2 中,路由参数可以自动映射到控制器参数,例如:http://a.com/test/foo will return "foo"
/**
* @Route("/test/{name}")
*/
public function action(Request $request, $name) {
return new Response(print_r($name, true));
}
见http://symfony.com/doc/current/book/routing.html#route-parameters-and-controller-arguments
但我想改用 查询字符串 例如:http://a.com/test?name=foo
如何做到这一点? 对我来说只有 3 个解决方案:
- 重新实现ControllerResolverInterface
- 使用自定义 ParamConverter
- $name = $request->query->get('name');
还有其他解决方案吗?
【问题讨论】:
标签: symfony