2017-05-14 58 views
1

我想在我的樹枝來加載每個用戶的圖像使用以下行:爲什麼圖像不能在Twig模板中加載?

<img src="/web/images/users/{{ topic.user.image }}" class="w3-circle" width="100" height="100"> 

。我肯定路徑是正確的。用戶頭像位於web/images/users /和選定的圖像中。那麼問題在哪裏呢?

真實顯示的:enter image description here

,這就是我如何嘗試上傳圖像文件中登記控制器:

/** @var UploadedFile $file */ 
       $file = $user->getImageForm(); 

       $filename = md5($user); 

       $file->move(
        $this->get('kernel')->getRootDir() . '/../web/images/users/', 
        $filename 
       ); 

       $user->setImage($filename); 
+0

你試過了嗎?src =「web/images/users/{{topic.user.image}}」....' – RiggsFolly

+0

是的,但仍然不起作用 –

+0

它呈現時的樣子是什麼。 – Musa

回答

1

你的Web服務器可能已經指向網頁目錄,所以儘量簡單:

<img src="images/users/{{ topic.user.image }}" class="w3-circle" width="100" height="100"> 

希望這有助於

NB:呦你可以嘗試調試轉儲topic.user.image的值,並檢查圖像存在的路徑。然後嘗試使用瀏覽器進行定位,看看會發生什麼。

+0

問題是我們服務器已經指向了網頁目錄,謝謝! –

相關問題