基础路由
URL 地址:
http://domain.com/my/page
对应的路由设置:
// app/routes.phpRoute::get('my/page', function(){ return 'Hello world!';});
可供使用的路由类型
Route::get();Route::post();Route::put();Route::delete();Route::any();
分别对应 GET
(查看) POST
(新增) PUT
(修改) DELETE
(删除) 这4种URL请求类型。
Route::any();
则是包含了以上4种请求类型。 使用外部定义的匿名函数
// app/routes.php$logic = function(){ return 'Hello world!';}Route::get('my/page', $logic);
使用路由参数
必填参数
// app/routes.phpRoute::get('/books/{genre}', function($genre){ return "Books in the {$genre} category.";});
以上路由指向 http://domain.com/books/crime
并且地址中 $genre
参数必须存在。
可选参数
// app/routes.php// routes for the books sectionRoute::get('/books/{genre?}', function($genre = 'Crime'){return "Books in the {$genre} category.";});
此时 http://domain.com/books/
也指向这个路由,并使用默认值 Crime
。