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