通过路由分组可以快速为具有共同属性的路由建立规则,例如:
~~~~~~
// 原型 router::group(array $in, $mixRouter);
router::group('公共属性', '路由或者闭包');
~~~
# 支持参数
公共属性包含以下多种情况,下面将一一说明。
## 路由域名
分组路由中可以指定域名,这样每一个路由都具备了域名匹配功能,域名中支持参数。
~~~
router::group ( [
'domain' => '{domain}.queryphp.com'
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
## 路由前缀
如果你需要为一个数组中的所有路由加上前缀,可以在路由中指定前缀 prefix。
~~~
router::group ( [
'prefix' => 'admin-'
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
访问地址
~~~
http://<service>/admin-hello-123456
~~~
解析后的 GET 值如下:
~~~
Array
(
[app] => home
[c] => goods
[a] => index
[goods] => 123456
)
~~~
## 附加参数
系统在匹配路由的时候,可以为匹配的结果附加上结果,解析变量的可以覆盖此值。
~~~
router::group ( [
'params' => [
'args1' => '小',
'args2' => '大'
]
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
访问地址
~~~
http://<service>/hello-123456
~~~
解析后的 GET 值如下
~~~
Array
(
[app] => home
[c] => goods
[a] => index
[args1] => 小
[args2] => 大
[goods] => 123456
)
~~~
## 参数正则
我们可以在分组中统一指定参数正则,路由内部的参数具有优先级。
~~~
router::group ( [
'where' => [
'id' => '[0-9]+',
'name' => '[a-z]+'
]
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
## 插入顺序
插入将在遇到相同路由的时候,具有优先匹配的权利。
~~~
router::group ( [
'prepend' => true
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
## 严格模式
严格模式让 url 匹配精准一些,请根据项目具体分析。
~~~
router::group ( [
'prepend' => true
], [
[
'new-{id}-{name}',
'home://new/index'
],
[
'hello-{goods}',
'home://goods/index'
]
] );
~~~
# 闭包注册
我们可以在分组路由中采用闭包注册路由,公共属性将会传入规则中。
~~~
router::group ( [
'prefix' => 'myprefix-'
], function () {
router::import ( 'new-{id}-{name}', 'home://new/index' );
router::import ( 'hello-{goods}', 'home://goods/index' );
} );
~~~
嵌套支持
~~~
router::group ( [
'prefix' => 'myprefix-'
], function () {
router::group ( [
'params' => [
'args1' => '你',
'args2' => '好'
]
], function () {
router::import ( 'new-{id}-{name}', 'home://new/index' );
router::import ( 'hello-{goods}', 'home://goods/index' );
} );
} );
~~~
- 关于 QueryPHP
- 获取 QueryPHP
- 环境要求
- 许可协议 Free
- 执行流程 MVC
- 命名规范 $sName
- 目录结构 DIR
- 单一入口 index.php
- 响应客户端请求 URL
- 命名空间与自动载入 Autoload
- 路由
- 路由导入
- 批量导入
- 参数正则
- 分组定义
- 路由绑定
- 路由域名
- 分层控制器
- 默认和初始化APP
- 默认控制器和方法
- url 模式
- url 生成
- url 伪静态
- url 重写
- url 重定向
- 控制器绑定
- 方法器分层
- 控制器 __init
- 控制器方法交互
- 模板引擎语法
- C变量输出 $sName
- C变量支持函数和方法 $sName|trim
- C快捷输出 ~
- C标签简化 Css & Javascript
- C默认值 eq 三元运算符
- C变量运算符 +-
- 变量递增递减 ++--
- C循环数据 list
- N变量赋值 assign
- N循环数据 list
- N循环数据高级版 lists
- C循环数据 while
- N循环数据 while
- C循环数据 for
- N循环数据 for
- C条件判断 if
- N条件判断 if
- 标签嵌套无限层级
- N循环流程 break & continue
- N使用 PHP 代码
- N包含子模板 include
- J模板引擎 intro
- J条件判断 if
- J循环数据 each
- J变量 & 表达式
- J变量支持函数和方法 hello|test
- J默认值 eq 三元运算符
- J框架前端组件 jquery.queryphp.js
- J前端 CSS 规范
- J前端 JS 规范
- 保护标签自身 tagself
- 数据库
- 数据库配置
- 执行原生 sql 语句
- 数据库事务
- 数据库构造器 prefix
- 数据库构造器 table
- 数据库构造器 forceIndex
- 数据库构造器 where
- 数据库构造器 bind
- 数据库构造器 join
- 数据库构造器 union
- 数据库构造器 orderBy
- 数据库构造器 groupBy
- 数据库构造器 having
- 数据库构造器 distinct
- 数据库构造器 aggregate
- 数据库构造器 limit
- 数据库构造器 forUpdate
- 数据库构造器 columns
- 数据库构造器 reset
- 数据库集合查询
- 数据库查询数据 get
- 数据库查询多条数据 getAll
- 数据库查询单条数据 getOne
- 数据库查询聚合查询 aggregate
- 数据库写入数据 insert
- 数据库写入数据 insertAll
- 配置
- 配置格式
- 惯性配置
- 配置文件
- 读取配置
- 设置配置
- 删除配置
- 日志
- 日志配置参数
- 日志路径
- 日志过滤器
- 日志处理器
- 缓存
- 缓存配置参数
- 缓存路径
- 缓存指定时间
- COOKIE
- COOKIE 配置参数
- 开发调试
- 页面 trace
