无法正确获得cssrewrite prod图像的资产

时间:2014-02-04 23:27:34

标签: css symfony rewrite assetic

使用Symfony和Assetic我无法在我的prod环境中正确地“转储”css图像。 他们继续链接回web / bundle / ... etc .. location。

我有一个非常基本的cssrewrite设置:

# 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"

我的模板:

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

我有app.php的prod版本,调试错误:

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);

我做了:

app / console assets:install --symlink

一切似乎都很好

然后我清除prod缓存

app / console assetic:dump --env = prod

我的css和js用预期的文件名复制出来,但是我的css中仍然出现url('../../bundle/..etc../images/bg.png');

在符号链接版本中,css为:url('../images/bg.png');

所以它必须与资产有关。

我期望'dump'ed css包含url('../ images / bg.png')等链接;

并将图像本身复制到web / images / 123abc.png

我是否应该从资产中获得这一点,如果是这样,我做错了什么?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

// In Config.yml file 

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

在app.php文件中

//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();