thinkPHP5 資源路由
阿新 • • 發佈:2019-01-11
5.0支援設定RESTFul請求的資源路由,方式如下:
Route:resource('blog','index/blog');
或者在路由配置檔案中使用rest新增資源路由定義:
return [
// 定義資源路由
'__rest__'=>[
// 指向index模組的blog控制器
'blog'=>'index/blog',
],
// 定義普通路由
'hello/:id'=>'index/hello',
]
設定後會自動註冊7個路由規則,如下:
標識 | 請求型別 | 生成路由規則 | 對應操作方法(預設) |
---|---|---|---|
index | GET | blog | index |
create | GET | blog/create | create |
save | POST | blog | save |
read | GET | blog/:id | read |
edit | GET | blog/:id/edit | edit |
update | POST | blog/:id | update |
delete | DELETE | blog/:id | delete |