Commit 65a8eae7 by Qiang Xue

Fixes #2399: Fixed the bug that AssetBundle did not handle relative URLs correctly

parent b2a2853e
...@@ -45,6 +45,7 @@ Yii Framework 2 Change Log ...@@ -45,6 +45,7 @@ Yii Framework 2 Change Log
- Bug #2298: Fixed the bug that Gii controller generator did not allow digit in the controller ID (qiangxue) - Bug #2298: Fixed the bug that Gii controller generator did not allow digit in the controller ID (qiangxue)
- Bug #2303: Fixed the bug that `yii\base\Theme::pathMap` did not support dynamic update with path aliases (qiangxue) - Bug #2303: Fixed the bug that `yii\base\Theme::pathMap` did not support dynamic update with path aliases (qiangxue)
- Bug #2324: Fixed QueryBuilder bug when building a query with "query" option (mintao) - Bug #2324: Fixed QueryBuilder bug when building a query with "query" option (mintao)
- Bug #2399: Fixed the bug that AssetBundle did not handle relative URLs correctly (qiangxue)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark) - Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark) - Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe) - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
......
...@@ -170,12 +170,13 @@ class AssetBundle extends Object ...@@ -170,12 +170,13 @@ class AssetBundle extends Object
list ($this->basePath, $this->baseUrl) = $am->publish($this->sourcePath, $this->publishOptions); list ($this->basePath, $this->baseUrl) = $am->publish($this->sourcePath, $this->publishOptions);
} }
$converter = $am->getConverter(); $converter = $am->getConverter();
$baseUrl = Yii::$app->getRequest()->getBaseUrl();
foreach ($this->js as $i => $js) { foreach ($this->js as $i => $js) {
if (strpos($js, '/') !== 0 && strpos($js, '://') === false) { if (strpos($js, '/') !== 0 && strpos($js, '://') === false) {
if (isset($this->basePath, $this->baseUrl)) { if (isset($this->basePath, $this->baseUrl)) {
$this->js[$i] = $converter->convert($js, $this->basePath, $this->baseUrl); $this->js[$i] = $converter->convert($js, $this->basePath, $this->baseUrl);
} else { } else {
$this->js[$i] = '/' . $js; $this->js[$i] = $baseUrl . '/' . $js;
} }
} }
} }
...@@ -184,7 +185,7 @@ class AssetBundle extends Object ...@@ -184,7 +185,7 @@ class AssetBundle extends Object
if (isset($this->basePath, $this->baseUrl)) { if (isset($this->basePath, $this->baseUrl)) {
$this->css[$i] = $converter->convert($css, $this->basePath, $this->baseUrl); $this->css[$i] = $converter->convert($css, $this->basePath, $this->baseUrl);
} else { } else {
$this->css[$i] = '/' . $css; $this->css[$i] = $baseUrl . '/' . $css;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment