靜態路由例子:php
use think\Route; // 註冊路由到index模塊的News控制器的read操做 Route::rule('new/:id','index/News/read'); 訪問http://serverName/new/5 直接路由到到http://serverName/index/news/read/id/5
動態帶參數路由:html
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+']], ];