【问题标题】:How to add a name to the route when using controller and not a function to route to in Laravel4?在 Laravel4 中使用控制器而不是路由到的函数时如何为路由添加名称?
【发布时间】:2013-03-18 06:14:53
【问题描述】:

我想,单行问题并不能很好地解释我在寻找什么。所以,这里是我所说的一个例子:(基于Laravel4 Routing documentation

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

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 中的控制器?

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    你可以用完全相同的方式命名你的路由到控制器。将控制器和方法名称作为“uses”关键字下数组中的第二项:

    Route::get('user/profile', array("as" => "profile", "uses" => "UserController@profile"));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    相关资源
    最近更新 更多