Yii Asset manager - css with image url

I am using the following code to publish my css file in assets.

Yii::app()->clientScript->registerCssFile( Yii::app()->assetManager->publish( Yii::getPathOfAlias('application').'/../css/combo-autocomplete.css' )); 

It successfully registers css and the styles work fine, but the next css class uses an image.

 .ui-icon { background-image: url(../images/down-arrow.png); } 

does not load, it refers to the path in the resource folder. He is looking for an image inside

root / assets / images /

Is there any way to redirect the image url in css to the source path, because I am not registering my images as assets at the moment.

root / image

+6
source share
1 answer

The Yii resource manager is designed to allow you to pack components such as user interface widgets offline (the alternative is to manually distribute various files in different places within the application directory structure). Therefore, if it makes sense to publish anything as an asset from your component, it makes sense to publish everything as an asset.

In this case, you should structure your component, for example. a

 component/ assets/ css/ images/ js/ 

Then publish the entire assets/ directory using the Yii asset manager, instead of publishing the files one by one. If you do, they will be published as

 assets/ random_hash/ css/ images/ 

Then your CSS can simply reference the images using url(../images/image.jpg) without knowing the random_hash value.

+11
source

Source: https://habr.com/ru/post/928025/


All Articles