From 6c08b6cfe17a6c3ea59fa28da411d004fb3ee7ea Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 22 Nov 2015 21:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=B7=AF=E7=94=B1=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/route.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library/think/route.php b/library/think/route.php index a20e9641..9fc152a9 100644 --- a/library/think/route.php +++ b/library/think/route.php @@ -65,7 +65,7 @@ class Route } } else { if (0 === strpos($rule, '[')) { - self::$rules[$type][substr(substr($rule, -1), 1)] = ['routes' => $route, 'option' => $option]; + self::$rules[$type][substr($rule, 1, -1)] = ['routes' => $route, 'option' => $option]; } else { self::$rules[$type][$rule] = ['route' => $route, 'option' => $option]; } @@ -75,7 +75,7 @@ class Route } // 路由分组 - public static function group($name, $routes = [], $type='*',$option = []) + public static function group($name, $routes = [], $type = '*', $option = []) { self::$rules[$type][$name] = ['routes' => $routes, 'option' => $option]; } @@ -201,7 +201,6 @@ class Route // 路由规则检测 if (!empty($rules)) { foreach ($rules as $rule => $val) { - $option = $val['option']; // 请求类型检测 if (isset($option['method']) && REQUEST_METHOD != strtoupper($option['method'])) { @@ -229,6 +228,9 @@ class Route } // 匹配到路由分组 foreach ($val['routes'] as $key => $route) { + if (is_numeric($key)) { + $key = array_shift($route); + } $regx1 = substr($regx, strlen($rule) + 1); if (0 === strpos($key, '/') && preg_match($key, $regx1, $matches)) { // 检查正则路由 @@ -242,6 +244,9 @@ class Route } } } else { + if (is_numeric($rule)) { + $rule = array_shift($val); + } // 单项路由 $route = $val['route']; if (0 === strpos($rule, '/') && preg_match($rule, $regx, $matches)) {