From 369bbc9d99405a3a0cf6c11e45e11ac563d29d3c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 23 Aug 2016 18:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=8A=A8=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=A0=87=E8=AF=86=E7=94=9F=E6=88=90=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=8D=E5=90=8C=E7=9A=84=E8=B7=AF=E7=94=B1=E8=A7=84?= =?UTF-8?q?=E5=88=99=20=E6=8C=87=E5=90=91=E5=90=8C=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A0=87=E8=AF=86=EF=BC=8C=E6=94=B9=E8=BF=9B?= =?UTF-8?q?Url=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=A0=87=E8=AF=86=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- library/think/Url.php | 21 +++++++++++---------- tests/thinkphp/library/think/urlTest.php | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 73b4b039..ad06d58f 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -301,7 +301,7 @@ class Route } $vars = self::parseVar($rule); if (isset($name)) { - self::$name[$name] = [$rule, $vars, self::$domain]; + self::$name[$name][] = [$rule, $vars, self::$domain]; } if ($group) { if ('*' != $type) { diff --git a/library/think/Url.php b/library/think/Url.php index d6237eb1..4e980adb 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -234,18 +234,19 @@ class Url // 匹配路由地址 public static function getRuleUrl($rule, &$vars = []) { - list($url, $pattern) = $rule; - foreach ($pattern as $key => $val) { - if (isset($vars[$key])) { - $url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url); - unset($vars[$key]); - } elseif (2 == $val) { - $url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url); - } else { - return false; + foreach ($rule as $item) { + list($url, $pattern) = $item; + foreach ($pattern as $key => $val) { + if (isset($vars[$key])) { + $url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url); + unset($vars[$key]); + return $url; + } elseif (2 == $val) { + return str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url); + } } } - return $url; + return false; } // 指定当前生成URL地址的root diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index 17651cb7..d8c748fd 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -56,7 +56,7 @@ class urlTest extends \PHPUnit_Framework_TestCase public function testBuildMethod() { - Route::get('blog/:id', ['\app\index\controller\blog', 'read']); + Route::get('blog/:id', '\app\index\controller\blog@read'); $this->assertEquals('/blog/10.html', Url::build('\app\index\controller\blog\read', 'id=10', 'html')); }