在 Laravel 3 中,我们可以调用Request::route()
来获取处理请求的主路由。
Laravel 4中是否有任何等价物?
L3 代码示例:
// in route.php
Route::any('TestRoute/(:any)', array('as' => 'NamedRoute', function() {
return print_r(Request::route());
}));
当我们访问
http://servername/TestRoute/123
我们得到
Laravel\Routing\Route Object (
[uri] => TestRoute/(:any)
[method] => GET
[bundle] => application
[controller] =>
[controller_action] =>
[action] => Array (
[as] => NamedRoute
[0] => Closure Object ( )
[https] =>
)
[parameters] => Array ( [0] => 123 )
)
我只对从上述对象中获取命名路由的名称感兴趣:
$namedRoute = $Route->action['as'];