2016-01-13 69 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不是一个数组