【发布时间】:2015-09-14 09:31:37
【问题描述】:
在 laravel 中,我可以使用以下内容在我的刀片模板中获取路线的当前名称:
{{ Route::currentRouteName() }}
如何在 Lumen 中做同样的事情?
【问题讨论】:
-
我不相信这是可能的,因为 Lumen 使用 nikic/FastRoute 进行路由,而不是 Laravel 使用的 Illuminate 包。
在 laravel 中,我可以使用以下内容在我的刀片模板中获取路线的当前名称:
{{ Route::currentRouteName() }}
如何在 Lumen 中做同样的事情?
【问题讨论】:
示例:
<?php
$method = Request::getMethod();
$pathInfo = Request::getPathInfo();
$currentRoute = $app->getRoutes()[$method.$pathInfo];
echo $currentRoute['action']['as'];
?>
测试版 5.0
【讨论】:
我解决了这个问题:
list($found, $routeInfo, $params) = app('request')->route() ?: [false, [], []];
$routeName = isset($routeInfo['as']) ? $routeInfo['as'] : null;
【讨论】: