如何在Laravel4中使用控制器而不是要路由到的函数时向路由添加名称


How to add a name to the route when using controller and not a function to route to in Laravel4?

我想,这一行问题并不能很好地解释我在寻找什么。所以,这里有一个我正在谈论的例子:(基于Laravel4路由文档)

我为控制器创建路由的方式:

Route::get('user/profile', "UserController@profile" );

我为路由创建名称的方式,以便以后在生成url时可以引用它:

Route::get('user/profile', array('as' => 'profile', function()
{
    //
}));
// Now I can use this
$url = URL::route('profile');

现在,显然你不想在routes.php中将控制器作为函数编写,那么我如何像第二个例子那样创建名称,但使用像例子1那样的控制器呢?

你也可以用同样的方式来命名你的路由。

将控制器和方法名称作为数组中uses关键字下的第二项
Route::get('user/profile', array("as" => "profile", "uses" => "UserController@profile"));