thinkphp路由配置route.php
路由设置配置
打开route.php
引入Route控制器类(use think\Route;)
设置路由--》 Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)');
打开route.php
引入Route控制器类(use think\Route;)
设置路由--》 Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)');
静态路由例子:
- use think\Route;
- // 注册路由到index模块的News控制器的read操作
- Route::rule('new/:id','index/News/read');
-
- 访问http://serverName/new/5 直接路由到到http://serverName/index/news/read/id/5
动态带参数路由:
- Route::rule('course/:id','index/index/course');
-
- // 批量注册GET路由
- Route::rule([
- '路由规则1'=>'路由地址和参数',
- '路由规则2'=>['路由地址和参数','匹配参数(数组)','变量规则(数组)']
- ...
- ],'','请求类型','匹配参数(数组)','变量规则');
-
- Route::get([
- 'new/:id' => 'News/read',
- 'blog/:id' => ['Blog/edit',[],['id'=>'\d+']]
- ...
- ]);
- // 效果等同于
- Route::rule([
- 'new/:id' => 'News/read',
- 'blog/:id' => ['Blog/edit',[],['id'=>'\d+']]
- ...
- ],'','GET');
-
- //等同于any方式
- return [
- 'new/:id' => 'News/read',
- 'blog/:id' => ['Blog/update',['method' => 'post|put'], ['id' => '\d+']],
- ];