企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
官方文档:https://www.kancloud.cn/manual/thinkphp5/118035 ## 设置自动7个路由规则系统提供的 <br/> | 标识 | 请求类型 | 生成路由规则 | 对应操作方法(默认) | | --- | --- | --- | --- | | 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 | PUT | `blog/:id` | update | | delete | DELETE | `blog/:id` | delete | ## 使用方法: 代码案例: -----------------------------------route.php文件里---------------------------- ~~~ <?php use think\Route; Route::resource('article','admin/article'); ~~~ ---------------admin/controller/Article.php文件里的内容--------------------- ~~~ <?php namespace app\admin\controller; class Article { public function index(){ dump( 'this is index'); } public function create() { dump( 'this is create'); } public function save() { dump( 'this is save'); } public function read() { dump( 'this is read'); } public function edit() { dump( 'this is edit'); } public function update() { dump( 'this is update'); } public function delete() { dump( 'this is delete'); } } ~~~ 按照生成路由规则添加写就行了 ~~~ http://127.0.0.1/index.php/article //默认访问idnex方法 http://127.0.0.1/index.php/article/128 //访问read方法 http://127.0.0.1/index.php/article/128 /edit //访问edit方法 ~~~ ![](https://img.kancloud.cn/33/6b/336b41ef7dd78607c327e2cd9ec122ab_1170x409.png) ## 注意:以上所有 article是自定义的 可以根据项目随便定义了 # 自动生成资源路由 ``` tp5根目录下执行 php think make:controller admin/Articlecontroller 就可以在admiin模块下生成资源路由 如果是index模块下就是 php think make:controller index/Articlecontroller ``` ![](https://img.kancloud.cn/3d/e6/3de6512e8eb1e00a893783e190a424e9_1919x920.png)