Symfony2 CSS图像路径被重写,我得到404

sti*_*vlo 5 css image yui-compressor symfony

我在现有项目中使用Symfony2和assetic,我无法弄清楚如何在CSS中引用图像.我把我的图片放在:src/Organisation/MyBundle/Resources/public/images/

运行资产安装后: php app/console assets:install public

我可以在浏览器中正确加载它们: http://sitename/bundles/organisationmy/images/logo.png

但是,当我尝试在CSS中指向它们时,使用: url('/bundles/organisationmy/images/logo.png')

用firebug检查,url变为:url('/web/bundles/organisationmy/images/logo.png')并且导致404.

在我的主模板中,我有:

{% stylesheets filter='yui_css' output='css/output.css'
    '@MyBundle/Resources/public/css/bootstrap.min.css'
    '@MyBundle/Resources/public/css/bootstrap-responsive.min.css'
    '@MyBundle/Resources/public/css/my.css'
 %}
Run Code Online (Sandbox Code Playgroud)

config.yml我有:

assetic:
    debug: %kernel.debug%
    use_controller: false
    java: /usr/bin/java
    filters:
        cssrewrite: ~
        yui_css:
            jar: %kernel.root_dir%/java/yuicompressor-2.4.7.jar
        yui_js:
            jar: %kernel.root_dir%/java/yuicompressor-2.4.7.jar
Run Code Online (Sandbox Code Playgroud)

routing.yml我有:

_assetic:
    resource: .
    type: assetic
Run Code Online (Sandbox Code Playgroud)

我已经看到了这个问题Symfony2 - Assetic - 在CSS中加载图像,但我不知道我是否以及如何使用filter='cssrewrite',filter='yui_css'同时或如何解决问题.

基本上,如果我可以阻止Symfony2前缀我的CSS图像路径/web/问题将得到解决.或者,是否有人知道在Symfony2中解决此问题的正确方法是什么?

更新:我注意到即使我把url('something.png')放在我加载页面时CSS也不再更新,所以我可能用命令行弄乱了一些东西,我也给了命令喜欢php app/console assetic:dump- 如何回到修改CSS并重新加载页面的正常开发风格?

更新2:我发现php app/console assetic:dump --watch在资产发生变化时会自动更新资产.

Dav*_*cia 8

为了在CSS文件中加载图像,路径必须是 "bundles/(bundle name)/images/(file name)"

UPDATE

确保你有

write_to: %kernel.root_dir%/../web 
Run Code Online (Sandbox Code Playgroud)

assetic:config.yml

background: url('/bundles/(bundle name)/images/prev.png') 在你的CSS

然后运行

php app/console assets:install web 
Run Code Online (Sandbox Code Playgroud)

php app/console assetic:dump web
Run Code Online (Sandbox Code Playgroud)