Rest 在Symfony2上,如何在RequestListener中检索被调用路由允许的HTTP方法?
一切都在标题中Rest 在Symfony2上,如何在RequestListener中检索被调用路由允许的HTTP方法?,rest,symfony,symfony-2.1,Rest,Symfony,Symfony 2.1,一切都在标题中 我希望在RequestListener中检索当前调用操作的批注中允许的HTTP@方法({“GET”,“POST”})。您必须在侦听器中获取路由器服务,并将当前路由名称$\u route传递到侦听器操作中 然后您将能够获得当前路线的要求: ... yourListenerAction(..., $_route) { ... $collection = $router->getRouteCollection(); $route = $collectio
我希望在RequestListener中检索当前调用操作的批注中允许的HTTP
@方法({“GET”,“POST”})
。您必须在侦听器中获取路由器
服务,并将当前路由名称$\u route
传递到侦听器操作中
然后您将能够获得当前路线的要求:
...
yourListenerAction(..., $_route)
{
...
$collection = $router->getRouteCollection();
$route = $collection->get($_route);
$requirements = $route->getRequirements();
$methods = $requirements['_method']; //will return string "GET|POST"
...