3
votes

Using Symfony and Assetic I cannot get css images to 'dump' correctly in my prod environment. They continue to link back to the web/bundle/...etc.. location.

I have a very basic cssrewrite setup:

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    filters:
        cssrewrite:
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

My template:

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

I have the prod version of app.php in place with debug false:

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$apcLoader = new ApcClassLoader('sf2', $loader);
$loader->unregister();
$apcLoader->register(true);
*/

require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

I have done:

app/console assets:install --symlink

All seems fine

Then I clear the prod cache

OK

app/console assetic:dump --env=prod

My css and js copy out with the expected file names, however I still have url('../../bundle/..etc../images/bg.png'); appearing in my css

In the symlinked version the css is: url('../images/bg.png');

So it must be something to do with assetic.

What I expect is for the 'dump'ed css to contain links like url('../images/bg.png');

And for the images themselves to be copied out to web/images/123abc.png

Should I expect this from assetic and if so what am I doing wrong?

Thanks, in advance.

1
It looks like you need to have relative links in your css or else assetic won't rewrite the images. Can anyone confirm if this is what I should expect?Henry
I have reviewed the documentation and it does in fact state that this is the case. I'm seriously face-palming myself for not seeing this earlier.Henry

1 Answers

1
votes
// In Config.yml file 

# Assetic Configuration 
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]

In app.php file

//If it is in dev environment In your app_dev.php file contain like this
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();

// If it is in prod environment, In your app.php file contain like this 
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();