thinkphp路由配置route.php

路由設置配置

打開route.php 
引入Route控制器類(use think\Route;)
設置路由--》  Route::rule('路由表達式','路由地址','請求類型','路由參數(數組)','變量規則(數組)');

靜態路由例子:php

  
  
  
  
  
  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

                動態帶參數路由:html

  
  
  
  
  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. ];
相關文章
相關標籤/搜索