2016-01-13 68 views
0

我有一個表媒體與列路徑和ALT,表POST是鏈接到表媒體。因此,如果用戶添加新帖子,則新帖子具有鏈接到表格媒體的圖像ID。我想呈現在我的網頁後的圖片,但我得到這個錯誤:從樹枝文件中的數據庫渲染圖像

這裏顯示的表之間的鏈接截圖:enter image description here

An exception has been thrown during the rendering of a template ("Notice: Undefined index: post") in src\FLY\BookingsBundle\Resources\views\Post\show.html.twig at line 18.

這是我做過什麼:

{% for post in post %} 
    <figure class="col-xs-3 col-sm-2"> 
    <span><img alt="airline" width="300" height="120" src="{{ post.image.path }}" ></span> 
</figure> 
{% endfor %} 

這是我PostController.php

public function showAction($id) 
    { 
     $em = $this->getDoctrine()->getManager(); 
     $user = $this->getUser(); 
     $findEntity = $em->getRepository('FLYBookingsBundle:Post')->findBy(array('user' => $user)); 
     $entity = $this->get('knp_paginator')->paginate($findEntity,$this->get('request')->query->get('page', 1),9 
     ); 

     if (!$entity) { 
      throw $this->createNotFoundException('Unable to find Post entity.'); 
     } 

     $deleteForm = $this->createDeleteForm($id); 

     return array(
      'entity'  => $entity, 
      'delete_form' => $deleteForm->createView(), 
     ); 
    } 
+0

'的showAction()'沒有變量稱爲'$ POST'和返回的數組沒有鍵值'post'的'post'。另外,'$ this-> getDoctrine() - > getManager() - > getRepository('FLYBookingsBundle:Post') - > findBy(array('user'=> $ user));'不向'showAction() - 它沒有分配給任何變量。 – geoB

+0

@geoB我確實找到了一種呈現圖像的方法,這就是我所做的:'{%爲實體%中的實體}

airline
{%endfor%}'。 – Sirius

+0

@ index.html.twig它使用他的圖像完美呈現產品。該索引必須顯示所有用戶的所有產品。但是,頁面show.html.twig必須僅呈現產品鏈接到他的ID,例如:http://127.0.0.1/symfony/web/app_dev.php/post/73,但它將產品鏈接呈現爲他的ID還有用戶登錄的產品與ID產品沒有鏈接。 – Sirius

回答

-1

您正在使用$entityPostController上,但是在樹枝上,您嘗試使用不存在的post

而且,你正在做一個foreach在可變的,但你應該只訪問它,因爲它可能只是一個對象或null不是一個數組