Symfony 2资产图片

时间:2012-11-10 16:36:44

标签: image symfony assets

我想在观看中添加资产图片。但如果我加载页面,图像将无法加载..

配置:

framework:
    esi:             ~
    translator:      { fallback: "%locale%" }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: "%kernel.debug%"
    form:            true
    csrf_protection: true
    validation:      { enable_annotations: true }
    templating:      { engines: ['twig'], assets_version: "1.0.0" }
    default_locale:  "%locale%"
    trust_proxy_headers: false # Whether or not the Request object should trust proxy headers (X_FORWARDED_FOR/HTTP_CLIENT_IP)
    session:         ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    read_from:      %kernel.root_dir%/../public_html
    write_to:       %kernel.root_dir%/../public_html
    use_controller: false
    #bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

index.html.twig

<img src="{{ asset('images/menu-park.gif') }}">

安装我运行的资产:

php app/console assets:install public_html --env=dev --symlink

我忘记了什么吗?

1 个答案:

答案 0 :(得分:22)

assets:install public_html命令将src/Acme/DemoBundle/Resources/public/目录复制到public_html/bundles/acmedemo/目录中。所以你需要引用那个网址。

例如:您有一个名为 MvParkBundle 的软件包,并且您已在menu-park.gif目录中创建了一个图像Resources/public/images,您应该在树枝内部使用此代码,假设前端控制器也位于public_html内:

<img src="{{ asset('bundles/mvpark/images/menu-park.gif') }}">

如果你运行assets:install public_html命令,一切都应该是正确的。