thinkphp路由配置route.php

路由设置配置

打开route.php 
引入Route控制器类(use think\Route;)
设置路由--》  Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)');

静态路由例子:

  1.                         use think\Route;
  2. // 注册路由到index模块的News控制器的read操作
  3. Route::rule('new/:id','index/News/read');
  4. 访问http://serverName/new/5 直接路由到到http://serverName/index/news/read/id/5

                动态带参数路由:

  1.                 Route::rule('course/:id','index/index/course');
  2. // 批量注册GET路由
  3. Route::rule([
  4. '路由规则1'=>'路由地址和参数',
  5. '路由规则2'=>['路由地址和参数','匹配参数(数组)','变量规则(数组)']
  6. ...
  7. ],'','请求类型','匹配参数(数组)','变量规则');
  8. Route::get([
  9. 'new/:id' => 'News/read',
  10. 'blog/:id' => ['Blog/edit',[],['id'=>'\d+']]
  11. ...
  12. ]);
  13. // 效果等同于
  14. Route::rule([
  15. 'new/:id' => 'News/read',
  16. 'blog/:id' => ['Blog/edit',[],['id'=>'\d+']]
  17. ...
  18. ],'','GET');
  19. //等同于any方式
  20. return [
  21. 'new/:id' => 'News/read',
  22. 'blog/:id' => ['Blog/update',['method' => 'post|put'], ['id' => '\d+']],
  23. ];




posted @ 2019-11-09 19:16  橱窗外的小孩  阅读(1887)  评论(0编辑  收藏  举报