From 869c70e0e739288312ec5c5c6892e55bf6441212 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 14 Jan 2016 14:20:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=B8=AD=E7=9A=84=E5=8F=98=E9=87=8F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E5=85=A8=E7=B1=BB=E5=9E=8B=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 5e9ef8a8..09e80d85 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -558,41 +558,26 @@ class Route array_shift($paths); } } - if (0 === strpos($url, '/') || 0 === strpos($url, 'http')) { - if (strpos($url, ':')) { - // 传递动态参数 - $values = array_values($matches); - $url = preg_replace('/:(\d+)/e', '$values[\\1-1]', $url); + // 替换路由地址中的变量 + foreach ($matches as $key => $val) { + if (strpos($url, ':' . $key)) { + $url = str_replace(':' . $key, $val, $url); + unset($matches[$key]); } + } + if (0 === strpos($url, '/') || 0 === strpos($url, 'http')) { // 路由到重定向地址 $result = ['type' => 'redirect', 'url' => $url, 'status' => (is_array($route) && isset($route[1])) ? $route[1] : 301]; } elseif (0 === strpos($url, '\\')) { // 路由到方法 - $result = ['type' => 'method', 'method' => $route, 'params' => $matches]; + $result = ['type' => 'method', 'method' => is_array($route) ? [$url, $route[1]] : $url, 'params' => $matches]; } elseif (0 === strpos($url, '@')) { - // 传递动态参数 - foreach ($matches as $key => $val) { - if (strpos($url, ':' . $key)) { - $url = str_replace(':' . $key, $val, $url); - unset($matches[$key]); - } - } // 路由到控制器 $result = ['type' => 'controller', 'controller' => substr($url, 1), 'params' => $matches]; } else { // 解析路由地址 $result = self::parseRoute($url); - // 解析路由地址中的变量 - foreach ($result['route'] as $key => $item) { - if (0 === strpos($item, ':')) { - $item = substr($item, 1); - if (isset($matches[$item])) { - $result['route'][$key] = $matches[$item]; - unset($matches[$item]); - } - } - } - $var = array_merge($matches, $result['var']); + $var = array_merge($matches, $result['var']); // 解析剩余的URL参数 self::parseUrlParams(implode('/', $paths), $var); // 路由到模块/控制器/操作