Yii资产管理器 - css与图像网址 [英] Yii Asset manager - css with image url
问题描述
我使用以下代码将我的CSS文件发布到资产。
I am using the following code to publish my css file to assets.
Yii::app()->clientScript->registerCssFile( Yii::app()->assetManager->publish( Yii::getPathOfAlias('application').'/../css/combo-autocomplete.css' ));
注册css成功并且样式工作正常,但下面的css类使用图像。
It registers the css successfully and styles are working fine, but the following css class using a image.
.ui-icon {
background-image: url(../images/down-arrow.png);
}
未加载,它被称为path inside assets文件夹。正在寻找
is not loading, it is referred to path inside assets folder. It is looking for the image inside
root / assets / images /
root/assets/images/
有没有办法将css中的图像网址重定向到原始路径,因为我没有将我的图片注册为现在的资产。
Is there any way to redirect the image url in the css to the original path, because i am not registering my images as assets as of now.
root / images
root/images
推荐答案
Yii的资产管理旨在让您以自包含的方式(替代方法是在应用程序目录结构中的不同位置手动分发各种文件)来封装组件(如UI小部件)。因此,如果从您的组件中将任何作为资产发布是有意义的,那么发布所有作为资产是有意义的。
Yii's asset manager is designed to let you package components such as UI widgets in a self-contained manner (the alternative being to manually distribute various files in different places inside your application directory structure). So if it makes sense to publish anything as an asset from your component, it makes sense to publish everything as an asset.
在这种情况下,你应该构造你的组件eg
In that case, you should structure your component e.g. as
component/
assets/
css/
images/
js/
然后,发布整个 assets /
目录,使用Yii的资产管理器,而不是逐个发布文件。如果你这样做,他们最终会以
Then, publish the whole assets/
directory using Yii's asset manager instead of publishing files one by one. If you do this, they will end up being published in a manner like
assets/
random_hash/
css/
images/
然后,您的CSS可以简单地引用 url(../ images / image.jpg)
,而不需要知道 random_hash
的值。
Your CSS can then simply refer to images with url(../images/image.jpg)
without needing to know the value of random_hash
.
这篇关于Yii资产管理器 - css与图像网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!