9

我想在我的视图中添加资产图像。但是如果我加载页面图像将不会加载..

配置:

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

我是不是忘记了什么?

4

1 回答 1

22

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

例如:您有一个名为MvParkBundlemenu-park.gif的包,并且您在目录中创建了一个图像Resources/public/images,您应该在 twig 中使用此代码,假设前端控制器public_html也在里面:

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

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

于 2012-11-10T17:05:26.877 回答