## 分組路由
分組路由可以把相同的信息或者相同的前綴放到同一個分組里可以提供匹配速度,該路由組件支持無限級子組,當然也不套太多層級,遞歸也是需要速度的。
[TOC]
#### 參數
~~~
/**
* 分組路由
* @param [array] $option [條件選項]
* @param [array] $route [路由地址 二維數組或者是一個閉包函數]
* @param [string] $method [請求方法]
* @param [array] $pattern [條件]
* @param [array] $name [分組名稱]
* @param [array] $pattern [匹配模式]
* @param [array] $behavior[匹配后的行為]
* @return [object] [$this]
*/
public function group($option, $route, $method = 'any', $pattern = [], $name = '', $behavior = [])
~~~
示例:
~~~
$route = [
'testgroup/{id}' => ['route' => 'index/index/create', 'where' => ['id' => '(\d{1})'], 'option' => [],'behavior'=>[]],
'testgroup/{uid}' => ['route' => 'index/index/delete', 'where' => ['uid' => '(\d{2})'], 'option' => [],'behavior'=>[]],
'testgroup/{aid}' => ['route' => 'index/index/update', 'where' => ['aid' => '(\d{3})'], 'option' => [],'behavior'=>[]],
];
Route::group('['prefix' => 'testgroup', 'method' => 'get']',$route, 'get' );
~~~
在配置文件可以這樣寫
~~~
// 分組路由
'group' => [
[
['prefix' => 'testgroup', 'method' => 'get'],
[
'testgroup/{id}' => ['route' => 'index/index/create', 'where' => ['id' => '(\d{1})'], 'option' => [],'behavior'=>[]],
'testgroup/{uid}' => ['route' => 'index/index/delete', 'where' => ['uid' => '(\d{2})'], 'option' => [],'behavior'=>[]],
'testgroup/{aid}' => ['route' => 'index/index/update', 'where' => ['aid' => '(\d{3})'], 'option' => [],'behavior'=>[]],
],
'get',
],
],
~~~
無限遞歸方式:
其實路由分組的注冊方法是簡介的調用了rules方法
如果rules方法的第一個參數為空,那么當前這一條路由規則的鍵名并不是批評規則,而是數字,系統判斷如果鍵名為數字表示一個分組路由,所有這樣間接的實現的無限子級。
~~~
// 分組路由
'group' => [
// 一個分組路由
[
['prefix' => 'testgroup', 'method' => 'get'],
// 分組路由第二個參數 路由規則 如果直接是規則就直接匹配如果想下面一一是一個二維數組就遞歸
[
[
'option'=>['prefix' => 'testgroup', 'method' => 'get'],
'route'=>[
'testgroup/{id}' => ['route' => 'index/index/create', 'where' => ['id' => '(\d{1})'], 'option' => [],'behavior'=>[]],
'testgroup/{uid}' => ['route' => 'index/index/delete', 'where' => ['uid' => '(\d{2})'], 'option' => [],'behavior'=>[]],
'testgroup/{aid}' => ['route' => 'index/index/update', 'where' => ['aid' => '(\d{3})'], 'option' => [],'behavior'=>[]],
],
'where' => [],
]
],
'get',
],
~~~
所以總的來說,路由分組不必調用分組方法,調用get post delete put any rules方法一樣可以實現
### 注意
如果使用路由分組并且存在子組由那么子組路由的參數必須齊全
- 簡介
- 開發規范
- 許可協議
- 作者
- 安裝框架
- 更新日志
- 基礎
- 入口文件
- 全局變量
- 系統配置
- 目錄結構
- 系統常量
- 自動加載
- 系統函數
- 應用密匙
- 依賴注入
- 配置
- 說明
- 基本使用
- 擴展應用
- C函數
- 容器
- 介紹
- 使用容器
- 綁定服務
- 數組訪問
- 請求
- 基礎
- 函數常量
- 獲取信息
- 方法偽造
- 路由
- 基礎使用
- 域名路由
- 靜態路由
- 正則路由
- 路由分組
- 地區
- 資源路由
- 閉包
- 其它方法
- 響應
- 響應輸出
- session
- 設置
- 生命周期數據
- cookie
- 加密使用
- 中間件(鉤子)
- 基礎使用
- 保存到文件
- 數據
- 配置
- 核心操作
- 聚合查詢
- 查詢構造器
- 關系型數據庫關聯
- 事務處理
- 日志
- 日志
- 視圖
- 模板配置
- 模板文件
- 模板語言
- 基礎使用
- 內置標簽
- 擴展標簽庫
- 模板
- 變量輸出
- 原樣輸出
- 運算符
- 緩存
- 緩存配置
- 基本操作
- 多語言
- 基礎使用
- 擴展庫
- 數據驗證
- xml
- 壓縮
- 工具類
- 字符串
- 文件上傳
- 目錄操作
- 二維碼
- 驗證碼
- 圖片處理
- curl
- url生成