2017-09-19 149 views
0

我想在我的樹枝來加載圖像,但它不顯示任何東西只顯示圖片ALT負荷圖像

這是我list.html.twig將加載圖像:

<img src="{{ asset('images/2.jpg') }}" alt="Symfony" /> 

,這是我的控制器:

<?php 
namespace AppBundle\Controller; 

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Response; 

class InheritanceController extends Controller 
{ 
    /** 
    * @Route("/inherit") 
    */ 
    public function inheritAction(){ 
     return new Response($this->render('article/list.html.twig')); 
    } 
} 

我的圖像文件夾在根目錄

+0

你是什麼意思的根目錄?你能展示或描述你的文件架構嗎? –

+0

@ t-n-y在symfony中的根目錄 – sepehr

回答

1

可以在樹枝使用asset()功能,只有當你的圖像上web/images文件夾存在的默認配置,那麼你可以通過{{ asset('images/<image_name>') }}

0

通過安裝資產控制檯:php app/console assets:install --symlink

0

的方法作出任何圖像的調用$this->render()已經返回Response實例,只需將其更改爲return $this->render(...)並再試一次。