7

在 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'];
4

1 回答 1

10

我想你可能对Route::currentRouteName();. 这是当前正在运行的路线的名称。

http://laravel.com/docs/routing#named-routes

于 2013-07-10T09:32:16.803 回答