tp5路由視頻https://ke.qq.com/webcourse/index.html#course_id=235325&term_id=100277509&taid=1539754365785917&vid=f1420a94f7r
1.支持三種方式的url解析規則
2.路由只針對應用,不針對模塊(路由設置也是針對應用下所有模塊)
3.如果某個模塊不進行路由解析,需要關閉它
例: //關閉admin模塊的路由(注意:寫在加載框架引導文件之后,否則報錯)
\think\App::route(false);

一:普通模式
定義:
完全使用PATH_INFO方式URL;
形式:
http://www.tp.com/admin.php/index/index(默認的,完整的,未設置的)
如何設置:
//配置文件中
~~~
//是否開啟路由
'url_route_on' => false,
//是否強制使用路由
'url_route_must' => falese,
~~~
二:混合模式
定義:
開啟路由,并使用路由定義+默認PATH_INFO方式混合
如何設置:
~~~
//是否開啟路由
'url_route_on' => true,
//是否強制使用路由
'url_route_must' => false,
~~~
三:強制模式
定義:
開啟路由,并必須設置路由才能訪問
如何設置:
//是否開啟路由
'url_route_on' => true,
//是否強制使用路由
'url_route_must' => true,
#### 設置路由
設置路由格式:
`Route::rule('路由表達式','路由地址','請求類型','路由參數(數組)','變量規則(數組)');`
1.動態單個注冊
1)配置文件:tp5\application\route.php
2)如何設置:
(設置了路由后的頁面不能使用PATH_INFO訪問)
3)路由的形式
a.靜態地址路由
//注冊路由test 訪問到index模塊index控制器test方法
` Route::rule('test','index/index/test');`
b.給路由帶參數
//訪問到index模塊index控制器course方法并攜帶參數
` Route::rule('course/:id','index/index/course');`
例:
路由寫法:http://www.tp.com/course/1
默認寫法:http://www.tp.com/index/index/course/id/1
c.攜帶多個參數
//如果路由設置2個參數,必須寫2個參數
//訪問到index模塊index控制器shijian方法
`Route::rule('time/:year/:month','index/index/shijian');`
d.可選參數路由
//month為可選參數
` Route::rule('time/:year/[:month]','index/index/shijian');`
e.全動態路由(參數1如果是其他方法,會優先訪問到其他方法中,所有不建議使用全動態路由)
`Route::rule(':a/:b','index/index/dongtai');`
f.完全匹配路由(后面加上$)
//后面多加參數什么的就無法訪問
` Route::rule('test1$','index/index/test1');`
g.帶額外參數
`Route::rule('test2','index/index/test2?id=10&name=zhangsan');`
//打印地址欄
dump(input());
4)路由的請求方式
1.get,post,put,delete
2.默認支持所有請求方式
//支持get請求
Route::rule('type','index/index/type','get');
Route::get('type','index/index/type');
//支持post請求
方法一:Route::rule('type','index/index/type','post');
方法二:Route::post('type','index/index/type');

//同時支持get和post
`Route::rule('type','index/index/type','get|post');`
//支持put請求類型
Route::rule('type','index/index/type','put');
Route::put('type','index/index/type);
//支持delete請求
Route::rule('type','index/index/type','delete');
Route::delete('type','index/inex/delete);
//支持所有類型
~~~
Route::rule('type','index/index/type','*');
Route::any('type','index/index/type');
~~~
小知識:
如何模擬請求(手冊請求偽裝)

2.動態批量注冊
Route::rule([
'路由規則1' => '路由參數和地址',
'路由規則2' => ['路由地址和參數',匹配參數(數組)','變量規則(數組)']
...
],'','請求類型','匹配參數(數組)','變量規則' );
例:
Route::rule([
"test" => "index/index/test",
"course/:id" => "index/index/course"
],'','get');
//只支持get
Route::get([
"test" => "index/index/test",
"course/:id" => "index/index/course"
]);
3.配置文件批量注冊
application\route.php

4.變量規則
Route::rule("course/:id/:name","index/index/course","get",[],['id'=>'\d{1,3}','name'=>'\w+']);
注: 正則
\d+ //必須為數字
\d{1,3} //必須為數字,并且1到3位數之間
\w+ //必須為字符串
5.路由參數
Route::rule("course/:id","index/index/course","get",['method'=>'get','ext'=>'html'],[]);
//路由參數method 規定請求方式必須是get
//路由參數ext 規定設置路由的后綴必須是html
6.資源路由
//聲明
Route::resource(
'blog','index/blog' );
//會自動注冊7個路由規則
| 標識 | 請求類型 | 生成路由規則 | 對應操作方法 |
| --- | --- | --- | --- |
| index | ge | blog | index |
| create | get | blog/create | create |
| save | post | blog | save |
| read | get | blog/:id | read |
| edit | get | blod/:id | edit |
| update | put | blod/:id | update |
| delete | delete | blod/:id | delete |
7.
- 空白目錄
- 關于頁面跳轉跟重定向
- thinkphp5return的問題
- thinkphp5權限auth
- thinkphp5關聯查詢多表查詢join
- javascript
- 數據庫命令行操作
- php間隔一段時間自動執行
- PHP字符串首尾留N位,中間替換成*號
- tp5獲取當前域名
- PHP常用函數
- 注冊發送短信驗證的接口詳解
- php可逆加密解密
- 配置本地虛擬主機
- thinkphp5跨控制器調用
- thinkphp5框架加載流程
- thinkphp5路由詳解
- thinkphp5功能集合
- thinkphp5數據庫操作
- delete,put類型
- tp5數據庫查詢
- tp5數據庫增刪改
- 事務機制
- thinkphp模型model新建和查詢
- tp5model的新增
- tp5model修改
- tp5model刪除和軟刪除
- tp5視圖
- tp5API