0
我有一個表媒體與列路徑和ALT,表POST是鏈接到表媒體。因此,如果用戶添加新帖子,則新帖子具有鏈接到表格媒體的圖像ID。我想呈現在我的網頁後的圖片,但我得到這個錯誤:從樹枝文件中的數據庫渲染圖像
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(),
);
}
'的showAction()'沒有變量稱爲'$ POST'和返回的數組沒有鍵值'post'的'post'。另外,'$ this-> getDoctrine() - > getManager() - > getRepository('FLYBookingsBundle:Post') - > findBy(array('user'=> $ user));'不向'showAction() - 它沒有分配給任何變量。 – geoB
@geoB我確實找到了一種呈現圖像的方法,這就是我所做的:'{%爲實體%中的實體} {%endfor%}'。 –
Sirius
@ index.html.twig它使用他的圖像完美呈現產品。該索引必須顯示所有用戶的所有產品。但是,頁面show.html.twig必須僅呈現產品鏈接到他的ID,例如:http://127.0.0.1/symfony/web/app_dev.php/post/73,但它將產品鏈接呈現爲他的ID還有用戶登錄的產品與ID產品沒有鏈接。 – Sirius