2012-11-10 104 views
8

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

配置:

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

你在img的src属性中获得的url是什么? – AdrienBrault

+0

回答

21

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

例如:您有一个名为MvParkBundle扎,你已经创建了Resources/public/images目录内的图像menu-park.gif,您应使用此代码里面树枝,假设前端控制器里面public_html太:

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

如果您运行assets:install public_html命令,则一切都应该正确。

+0

但为什么--symlink不起作用?它应该是一样的? –

+0

您也可以使用--symlink,但是您需要将Twig模板中的路径更改为“bundles/{bundlename}/images/menu-park.gif”。 –

+2

问题是:'app/console assets:install public_html' works,但'app/console assets:install public_html --symlink' does not work .. but why:S –