thinkphp URL 路径格式
http://serverName/index.php/module/controller/action/[param/value...]
http://localhost/tp5/public/index.php/index/index/index
[对于某些环境不支持]
兼容模式
http://serverName/index.php?s=module/controller/action/p/v...
缺点
- 太长
- URL路径暴露出服务器文件结构
- 不够灵活
- 不能很好的支持URL语义化(最大缺陷)
tp5自定义路由 Route.php
路由模式
Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)')
请求类型
类型 | 描述 | 快捷方法 |
---|---|---|
GET | GET请求 | get |
POST | POST请求 | post |
PUT | PUT请求 | put |
DELETE | DELETE请求 | delete |
PATCH | PATCH请求 | patch |
* | 任何请求类型 | any |
路由参数
参数 | 说明 | 方法名 |
---|---|---|
method | 请求类型检测,支持多个请求类型 | method |
ext | URL后缀检测,支持匹配多个后缀 | ext |
deny_ext | URL禁止后缀检测,支持匹配多个后缀 | denyExt |
https | 检测是否https请求 | https |
domain | 域名检测 | domain |
before | 前置行为(检测) | before |
after | 后置行为(执行) | after |
merge_extra_vars | 合并额外参数 | mergeExtraVars |
complete_match | 是否完整匹配路由 | completeMatch |
model | 绑定模型 | model |
cache | 请求缓存 | cache |
param_depr | 路由参数分隔符 | depr |
ajax | Ajax检测 | ajax |
pjax | Pjax检测 | pjax |
response | 绑定response_send行为 | response |
validate | 绑定验证器类进行数据验证 | validate |
header | 设置Response的header信息 | header |
append | 追加额外的参数(5.1.5+ ) | append |
middleware | 注册路由中间件(5.1.6+ ) | middleware |
merge_rule_regex | 合并路由规则(V5.1.6+ ) | mergeRuleRegex |
filter | 请求变量过滤(V5.1.16+ ) | filter |