Laravel 4 : Route to localhost/controller/action

前端 未结 3 2038
终归单人心
终归单人心 2020-12-03 15:43

I\'m more or less new to Laravel 4. I\'ve never used routes before but normally what I\'m used to is url/controller/action and then the backend routing for me. I\'ve read th

3条回答
  •  借酒劲吻你
    2020-12-03 16:28

    app\
        controllers\
            Admin\
               AdminController.php
            IndexController.php
    
    Route::get('/admin/{controller?}/{action?}', function($controller='Index', $action='index'){
            $controller = ucfirst($controller);
            $action = $action . 'Action';
            return App::make("Admin\\{$controller}Controller")->$action();
        });
    
    Route::get('/{controller?}/{action?}', function($controller='Index', $action='index'){
            $controller = ucfirst($controller);
            $action = $action . 'Action';
            return App::make("{$controller}Controller")->$action();
        });
    

提交回复
热议问题