修正Url类一处Bug

This commit is contained in:
thinkphp
2016-08-23 18:11:28 +08:00
parent 369bbc9d99
commit 64bea5c8d2

View File

@@ -78,9 +78,9 @@ class Url
}
if (!empty($rule) && $match = self::getRuleUrl($rule, $vars)) {
// 匹配路由命名标识 快速生成
$url = $match;
if (!empty($rule[2])) {
$domain = $rule[2];
$url = $match[0];
if (!empty($match[1])) {
$domain = $match[1];
}
} elseif (!empty($rule) && isset($name)) {
throw new \InvalidArgumentException('route name not exists:' . $name);
@@ -235,14 +235,15 @@ class Url
public static function getRuleUrl($rule, &$vars = [])
{
foreach ($rule as $item) {
list($url, $pattern) = $item;
list($url, $pattern, $domain) = $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;
return [$url, $domain];
} elseif (2 == $val) {
return str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url);
$url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url);
return [$url, $domain];
}
}
}