Laravel 4:基于URI的路由

时间:2014-02-26 19:16:05

标签: laravel laravel-4 uri laravel-routing

民间,

我正在尝试做一些简单的事情。例如,在我的“设置”导航中,如下所示:

http://localhost/settings/   
http://localhost/settings/general
http://localhost/settings/message
http://localhost/settings/users

这有可能以任何方式让我的路由器知道当它看到设置/用户时,我想要它去SettingsController @ users吗?和settings / general转到SettingsController @ general

事情是,我不想在routes.php中放下每个网址,如:

Route::any("settings/users", array("as" => "users", "uses" => "SettingsController@users"));
Route::any("settings/general", array("as" => "general", "uses" => "SettingsController@general"));

这有可能吗?

1 个答案:

答案 0 :(得分:0)

您需要在routes.php中使用Route Controller,如

Route::controller('settings', 'SettingsController');

并在您的SettingsController中定义以下方法。

class SettingsController extends BaseController {

    //URL : http://localhost/settings
    public function getIndex()
    {
        echo 'Index Method';

    }

    //URL : http://localhost/settings/message
    public function getMessage()
    {
        echo 'Message Method';
    }
}

你必须使用'get'前缀并以Upper字符开头。有关详细信息,请查看http://laravel.com/docs/controllers#restful-controllers