douoyou3348 2016-02-25 02:39
浏览 36
已采纳

Laravel 5.2路由像cakephp

I am new to laravel. I am coming form cakephp, so routing is creating a bit of difficulty for me.

I have tried the Question but getting error in that. I also tried for Route::controller(); and Route::resource(); but not getting the the result i want.

I simply want the rounting to be

http://example.com/controller/action/param1/param2/param3

also, if i can get answer for the backend management like

http://example.com/backend/controller/action/param1/param2/param3
  • 写回答

4条回答 默认 最新

  • donjd86266 2016-02-25 03:19
    关注

    In Laravel 5.2 the use of Route::controller('Controller') has been deprecated due to annoying race conditions.

    To get your desired result. Let's say you have a controller App\Http\Controllers\MyController.

    In your routes.php file you would have the following:

    Route::group(['middleware' => ['web']], function(Router $router) {
    
        // Note the question marks after the parameters
        // this makes them optional.
        $router->get('uri/{action?}/{param1?}/{param2?}', [
            'uses' => 'MyController@getIndex'
        ]);
    });
    

    You would now have a controller method getIndex

    // As the parameters were optional, make sure to give them
    // default values.
    public function getIndex($action = null, $param1 = null, $param2 = null)
    {
        // Your route logic
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部