Laravel 4 如何使用路由名称别名(使用)与 Route::controller

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20545502/
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 08:45:16  来源:igfitidea点击:

Laravel 4 how to use the route name alias (uses) with Route::controller

laravellaravel-4

提问by James

Rather than using Route::get, Route::postetc for my controller requests I decided to use the Route::controllermethod, really helps cut down on code lines in route.php.

而不是使用Route::getRoute::post等我控制器请求我决定使用Route::controller方法,确实有助于减少在代码行route.php

However I had previously set up some "route" names, for example my previous code included:

但是我之前已经设置了一些“路线”名称,例如我之前的代码包括:

Route::get('admin/baserate/view', array('as' => 'baserateview','uses'=>'BaserateController@getView'));

but now I'm using Route::controllerI don't know how to implement the route alias name "baserateview". My new code looks like:

但现在我正在使用Route::controller我不知道如何实现路由别名“baserateview”。我的新代码如下所示:

Route::controller('admin/baserate', 'BaserateController');

Is there any way I can do this?

有什么办法可以做到这一点吗?

回答by Andrew Halls

You can do this in the following way:

您可以通过以下方式执行此操作:

// User Controller
Route::controller(
    'users',
    'AdminUserController',
    array(
        'getView'     => 'admin.users.view',
        'getEdit'     => 'admin.users.edit',
        'getList'     => 'admin.users.list',
        'getAdd'      => 'admin.users.add',
        'getUndelete' => 'admin.users.undelete',
        'postDelete'  => 'admin.users.delete'
    )
);

回答by James

Ok so it isn't possible to do it all on the Route:controller line. I'd have to go with both lines:

好的,所以不可能在 Route:controller 线上完成所有操作。我必须同时使用两条线:

Route::controller('admin/baserate', 'BaserateController');
Route::get('admin/baserate/view', array('as' => 'baserateview','uses'=>'BaserateController@getView'));

...which works fine. I was just hoping that there would be a way to specify that one of the methods inside the controller has a named route without having to use two lines

...这工作正常。我只是希望有一种方法可以指定控制器内的一个方法具有命名路由,而不必使用两行

Thanks anyway

不管怎么说,还是要谢谢你