繁体   English   中英

在Symfony2上,如何在RequestListener中检索允许的被调用路由的HTTP方法?

[英]On Symfony2, how to retrieve in a RequestListener the allowed HTTP Methods of the called route?

全部都在标题中,

我想在RequestListener中检索当前称为Action的注释中允许的HTTP @Method({"GET", "POST"})

您必须在侦听router中获得router服务,并将当前路由名称$_route到侦听器操作中。

然后,您将能够获得当前路线的要求:

...
yourListenerAction(..., $_route)
{
    ...

    $collection = $router->getRouteCollection();
    $route = $collection->get($_route);
    $requirements = $route->getRequirements();

    $methods = $requirements['_method']; //will return string "GET|POST"

    ...

暂无
暂无

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

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