diff --git a/helper.php b/helper.php index 007c76cd..e0cc719e 100644 --- a/helper.php +++ b/helper.php @@ -277,7 +277,7 @@ if (!function_exists('url')) { * @param bool|string $domain 域名 * @return string */ - function url($url = '', $vars = '', $suffix = true, $domain = true) + function url($url = '', $vars = '', $suffix = true, $domain = false) { return Url::build($url, $vars, $suffix, $domain); } diff --git a/library/think/Url.php b/library/think/Url.php index 87a79ed0..b4ae0aac 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -30,8 +30,11 @@ class Url * @param boolean|string $domain 是否显示域名 或者直接传入域名 * @return string */ - public static function build($url = '', $vars = '', $suffix = true, $domain = true) + public static function build($url = '', $vars = '', $suffix = true, $domain = false) { + if (false === $domain && Route::rules('domain')) { + $domain = true; + } // 解析URL if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { // [name] 表示使用路由命名标识生成URL @@ -194,7 +197,6 @@ class Url self::$bindCheck = true; $url = substr($url, $pos[$domain]); } - } elseif ($domain) { if (isset($domains[$domain]['[bind]'][0])) { $bindModule = $domains[$domain]['[bind]'][0]; diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index ced519d7..acb43365 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -25,13 +25,13 @@ class urlTest extends \PHPUnit_Framework_TestCase public function setUp() { - Route::rules(['GET' => [], - 'POST' => [], - 'PUT' => [], - 'DELETE' => [], - 'PATCH' => [], - 'HEAD' => [], - 'OPTIONS' => [], + Route::rules(['get' => [], + 'post' => [], + 'put' => [], + 'delete' => [], + 'patch' => [], + 'head' => [], + 'options' => [], '*' => [], 'alias' => [], 'domain' => [],