Laravel 4 中 Request::route() 的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16913251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:52:44  来源:igfitidea点击:

What is the equivalent of Request::route() in Laravel 4?

phplaravellaravel-4

提问by igaster

In Laravel 3 we could call Request::route()to get the main route handling the request.

在 Laravel 3 中,我们可以调用Request::route()以获取处理请求的主路由。

Is there any equivalent in Laravel 4?

Laravel 4 中是否有任何等价物?

Example of L3 code:

L3代码示例:

// in route.php
Route::any('TestRoute/(:any)', array('as' =>  'NamedRoute', function() {
    return print_r(Request::route());
}));

When we visit

当我们访问

http://servername/TestRoute/123

we get

我们得到

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 ) 
)

I am only interested to get the name of a Named Route from the above Object:

我只对从上述对象中获取命名路由的名称感兴趣:

$namedRoute = $Route->action['as'];

回答by Bitbored

I think you might be interested in Route::currentRouteName();. This get's the name of the route that is currently running.

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

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

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