css rewrite , concerned with less and yui

I have a problem really odd about css rewrite.
suppose we have a css in AcmeTestBundle/Resources/public/css folder, named a.less. In this a.css we have a rule like:
    background: url(../images/buttons.png) no-repeat top left;
which is the AcmeTestBundle/Resources/public/images/button.png, for some ugly reasons, if we use symfony2 assetic, the cssrewrite can not translate it correctly, so we use this commmand first ;
php app/console assets:install
and then in our layout.twig, we can use this:
    {% stylesheets 
   'bundles/acmetest/css/*.less'
   filter='lessphp,cssrewrite,?yui_css'
         output='css/test.css' %}
            
    {% endstylesheets %}   

well, the odd thing come, we get a web/css/test.css, and in this file, we have a image link like this:
background: url((../../bundles/acmetest/images/buttons.png) no-repeat top left;
if your site url is the root of the domain, no problem, like you have a domain name : www.abcefg.com. But, if you use some alias folder for you symfony2 project, like www.abcdefg.com/test/ as the root of your project,cause your button.png url indeed is www.abcdefg.com/test/bundles/acmetest/images/buttons.png, but this css will point to www.abcdefg.com/bundles/acmetest/images/button.png which does not exist.
i do some test, first, if i make the assetic like this:
    {% stylesheets 
   'bundles/acmetest/css/*.less'
   filter='lessphp,cssrewrite,?yui_css'
         output='css/test/test.css' %}
            
    {% endstylesheets %}   
i'll get a css file located in web/css/test/test.css, and the generated path is still the same, everything works fine.
second, if i change the less file:
background: url(../images/buttons.png) no-repeat top left;
i'll get the generated css file which point to
../../bundles/acmetest/css/images/buttons.png)
so this is not what i want.
Here we need to say the problem come from the seting of assetic. Then i reset the assetic as origin:
    {% stylesheets 
   'bundles/acmetest/css/*.less'
   filter='lessphp,cssrewrite,?yui_css'
         output='css/test/test.css' %}
            
    {% endstylesheets %}  
and i got the right css:
../bundles/acmetest/css/images/buttons.png)
So i think maybe this is a problem of cache, but I have already cleared several times before
    php app/console assetic:dump

评论

热门帖子