How to add a prefix to the reference asset?


Any idea how to do this - to add a prefix to the url of assets after they sign up? For example, I regau SomeAssetBundle which is published statics from $sourcePath. Get the path /assets/%hash%/%filename% after it posted. The task is to add the prefix in the received path, for example /test/assets/%hash%/%filename%
June 3rd 19 at 19:24
2 answers
June 3rd 19 at 19:26
Setting a baseUrl can only be used if there is no parameter $sourcePath, as stated in the documentation:
But I need to use a custom physical path and change the url of assets.

Yes, I inherit from the class AssetBundle - Clovis commented on June 3rd 19 at 19:29
June 3rd 19 at 19:28
Expanded class SomeAssetBundle method
 * Adds a prefix to the url
 * @param string $prefix the prefix of the reference
 public function updateBaseUrl($prefix)
 $this->baseUrl = DIRECTORY_SEPARATOR . $prefix . $this->baseUrl;

And then at the registration stage, gave this method the desired prefix:
$bundle = test\components\SomeAssetBundle ::register($this);
could be more in the assets, to cling to init
public function init()
 $this->baseUrl = DIRECTORY_SEPARATOR . $this->prefix . $this->baseUrl;
- Clovis commented on June 3rd 19 at 19:31

Find more questions by tags Yii