Yii 资产管理器 - 带有图像 url 的 css [英] Yii Asset manager - css with image url

查看:18
本文介绍了Yii 资产管理器 - 带有图像 url 的 css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将我的 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); 
}

未加载,它指的是资产文件夹内的路径.它正在寻找里面的图像

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 中的图像 url 重定向到原始路径,因为我现在还没有将我的图像注册为资产.

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.

根目录/图像

推荐答案

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.

在这种情况下,您应该构建您的组件,例如作为

In that case, you should structure your component e.g. as

component/
    assets/
        css/
        images/
        js/

然后,使用 Yii 的资产管理器发布整个 assets/ 目录,而不是一个一个地发布文件.如果你这样做,它们最终会以类似的方式发布

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 资产管理器 - 带有图像 url 的 css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆