laravel路由定义

参考http://www.ruchee.com/notes/fms/laravel_primer.htmlphp

 

路由

路由定义位置在 app/routes.php 文件,支持五种路由方法,采用回调函数的形式工做:html

Route::get()
Route::post()
Route::put()
Route::delete()
Route::any()

 

至关重要的一点:路由是区分大小写的,/hello 和 /Hello 是不一样的路由laravel

能够用 {} 对路由进行命名,如:数组

Route::get('/hello/{name}', function ($name) {
    return "Hello, {$name}";
});

 

还能够在命名路由后加一个 ? 号,表示该路由无关紧要,如:app

Route::get('/hello/{name?}', function ($name) {
    return "Hello, {$name}";
});
// 但须要注意的是,若是 $name 没有赋默认值,则访问 /hello 路径会出错

能够经过 
 使用模版,如:View::make
Route::get('/hello/{name?}', function ($name = 'Laravel') {
    $data['name'] = $name;
    return View::make('hello', $data);
});
// 上述代码会用 $data 数组去填充 app/views 目录下的 hello.php 文件

 

其余用法函数

跳转:Redirect::to('须要跳转到的路由')
自定义响应:Response::make('响应内容', HTTP状态码)
相关文章
相关标签/搜索