0
我試圖在我的動作中獲取當前路線模式,因爲您可以在debug:router
命令中獲得。當前路線模式
all_medias GET ANY ANY /api/media/all.{_format}
我看了在RouterDebugCommand
,但你需要一個$input
和$ouput
對象使用助手。這似乎有點過於複雜的任務。有沒有辦法從控制器獲取路由模式?
我試圖在我的動作中獲取當前路線模式,因爲您可以在debug:router
命令中獲得。當前路線模式
all_medias GET ANY ANY /api/media/all.{_format}
我看了在RouterDebugCommand
,但你需要一個$input
和$ouput
對象使用助手。這似乎有點過於複雜的任務。有沒有辦法從控制器獲取路由模式?
您可以按名稱從RouteCollection
獲取路線$currentRouteName = $request->attributes->get('_route');
$currentRoutePath = $this->get('router')->getRouteCollection()->get($currentRouteName)->getPath();
或者你也可以檢查其模式(自2.2 deprated):
$currentRoutePattern = $this->get('router')->getRouteCollection()->get($currentRouteName)->getPattern();