来自css资产的404错误在dev中被调用

时间:2013-11-07 22:28:29

标签: css url symfony assetic assets

我不明白为什么,但由于Assetic,我的捆绑图片没有被正确调用。 我试着用它来实现:

background-image: url('../images/bg-header-1.jpg');

在我的VisualImmersion / SiteBundle / Resources / public / css / home.css中,我的图片在:VisualImmersion / SiteBundle / Resources / public / images / bg-header-1.jpg

我认为我在总体布局中使用了很好的资产方法:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="robots" content="follow">
        <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'/>
        <title>{% block title %} Visual Immersion - Agence de communication {% endblock %}</title>
        <meta name="description" content="Agence de communication | Développement web - Référencement SEO / Adwords - Développement mobile / tablettes - Brand design - Community Management - Evènementiel ">
        <link rel="icon" type="image/png" href="{{ asset('css/images/favicon.png') }}"/>
        {% stylesheets filter= 'cssrewrite'
            'css/stylesheets/layout.css'
            'css/stylesheets/style.css'
            'css/stylesheets/font.css'
            'css/stylesheets/responsive.css'
            'css/stylesheets/personalized-responsive.css'
            '@VisualImmersionSiteBundle/Resources/public/css/*'
        %}
            <link rel="stylesheet" type="text/css" href="{{ asset_url }}">

        {% endstylesheets %}
        {% block javascripts %}
            <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
            <script src="http://twitterjs.googlecode.com/svn/trunk/src/twitter.min.js"></script>
            <script>
                (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
                })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

                ga('create', 'UA-41814706-1', 'visual-immersion.com');
                ga('send', 'pageview');

            </script>
        {% endblock %}
    </head>

但没有形象......

提前感谢您的帮助

编辑:我的dev_config.yml

imports:
    - { resource: config.yml }

framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"
        strict_requirements: true
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        firephp:
            type:  firephp
            level: info
        chromephp:
            type:  chromephp
            level: info

assetic:
    use_controller: true
    filters:
        cssrewrite: ~

那是我的6de3e66_part_6_home_1.css:

background-image: url('../../Resources/public/images/bg-header-1.jpg');

2 个答案:

答案 0 :(得分:0)

在这里查看我的答案CSS/JS/Images from Bundle location will be always removed after composer.phar update

我解释了如何使用Resources / public目录来管理图像等资产。

答案 1 :(得分:0)

好的,我做了一些测试:

我将cssrewrite删除到了我的config_dev.yml。 它:

imports:
    - { resource: config.yml }

framework:
    router:
        resource: "%kernel.root_dir%/config/routing_dev.yml"
        strict_requirements: true
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        firephp:
            type:  firephp
            level: info
        chromephp:
            type:  chromephp
            level: info

assetic:
    use_controller: true

我在我的总体布局中将注释移出了cssrewrite过滤器:

{% stylesheets '@VisualImmersionSiteBundle/Resources/public/css/*'  filter='cssrewrite'
    'css/stylesheets/layout.css'
    'css/stylesheets/style.css'
    'css/stylesheets/font.css'
    'css/stylesheets/responsive.css'
    'css/stylesheets/personalized-responsive.css'
%}
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}">

{% endstylesheets %}

我将css中的资产路径更改为:

background-image: url('/bundles/visualimmersionsite/images/bg-header-1.jpg');

它有效!

但我的问题是:现在它在dev env上工作,好吧,很好。但是当我进入生产环境时,这种方法确实会带来问题吗?