当 'assetic:dump' 为 运行 时,Assetic(使用 Symfony 2)更改图像文件的名称

Assetic (with Symfony 2) changes the name of image files when 'assetic:dump' is run

每当我 运行 命令 php app/console assetic:dump 我的所有资产(css、javascript、图像)都成功地放入 web/ 文件夹中。我遇到的唯一问题是 Assetic 更改了图像文件名,大概是为了缓存破坏目的,这会干扰我的 css 文件中引用的图像。

当我手动将图像放入 web/images/masthead-4.jpg 时,它会正确显示。如果可能的话,我想让缓存破坏图像。 我希望使用以下解决方案之一:

我的图像位于 %kernel.root_dir%/app/Resources/public/images。 例如,假设我有一个文件 %kernel.root_dir%/app/Resources/public/images/masthead-4.jpg


图像文件 php app/console assetic:dump 的输出是:

20:22:40 [file+] /our_stuff/admin/symfony/app/../web/images/d755b65-aa84794.jpg
20:22:40 [file+] /our_stuff/admin/symfony/app/../web/images/d755b65-aa84794_masthead-4_1-86f4322.jpg

现在文件已命名为 d755b65-aa84794_masthead-4_1-86f4322.jpgd755b65-aa84794.jpg 我的 background-image css 规则找不到图像。


我的后台 CSS 规则位于 %kernel.root_dir%/app/Resources/public/images

    .is--site_landing {
      background: transparent url('../images/masthead-4.jpg') top center no-repeat;
      background-size: cover;
    }

我的 header 在我的 Twig 布局文件中:

{% stylesheets
  'css/style.css.scss'
  filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

{% javascripts
  'js/jquery-1.11.2.min.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}  

{%image 
  'images/masthead-4.jpg'
%}
{% endimage %}

更多信息: 我是 运行宁:

A​​ssetic是为处理资产而制作的。如果您不喜欢它来处理您的图像,请不要将其用于图像。

首先,删除它,你不需要它。

{%image 
  'images/masthead-4.jpg'
%}
{% endimage %}

接下来,使用 php app/console assets:install --symlinkweb 文件夹中创建符号链接。这样,您的 CSS 文件就可以访问图像文件了。