P
P
Pavel Tuzov2018-07-20 10:16:22
Yii
Pavel Tuzov, 2018-07-20 10:16:22

How to add a prefix to an asset link?

Greetings.
Any ideas how to do the following - add a prefix to the url of assets after registering them? For example, I register SomeAssetBundle in which statics from $sourcePath are published. I get the path /assets/%hash%/%filename% after publishing. The task is to add a prefix in the received path, for example /test/assets/%hash%/%filename%

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-07-20
@PavelTuzov

https://www.yiiframework.com/doc/api/2.0/yii-web-a...

P
Pavel Tuzov, 2018-07-20
@PavelTuzov

Extended the SomeAssetBundle class with the method

/**
     * Добавляет префикс к урлу
     *
     * @param string $prefix Префикс ссылки
     */
    public function updateBaseUrl($prefix)
    {
        $this->baseUrl = DIRECTORY_SEPARATOR . $prefix . $this->baseUrl;
    }

And then at the registration stage, I passed the required prefix to this method:
$bundle = test\components\SomeAssetBundle ::register($this);
$bundle->updateBaseUrl('test');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question