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 |