用树枝展示教义集? (Symfony2)
我有一个非常简单的代表新闻的学说实体;这个新闻可以与很多图片联系起来,所以我决定使用教义集。问题是,我想检索这些图片并将它们显示在我的模板中......但它似乎不起作用。你知道我该怎么做吗?
这是我尝试过的:
{% for annonce in annonces %}
<div class="annonce_item">
{% for photo in annonce.photo %}
<img src="{{ photo.path }}" alt="" />
{% endfor %}
</div>
<!-- End .annonce_item -->
{% endfor %}
annonce 是新闻类,photo 是集合:
/**
* @ORM\OneToMany(targetEntity="Photo", mappedBy="id",cascade={"persist"})
*/
private $photo;
当我尝试在浏览器中显示此页面时,出现以下异常:
渲染模板期间抛出异常(“注意:未定义索引:>id in >/Applications/MAMP/htdocs/ApacheImmobilier/vendor/doctrine/lib/Doctrine/ORM/Persisters/Basi>” cEntityPersister.php 第 1274 行”)位于“APPagesBundle:Index:index.html.twig”第 45 行。
谢谢!
I have a quite simple doctrine entity that represent a news ; this news can be linked with many pictures, so I decided to use a Doctrine Collection. The thing is, I want to retrieve this pictures and display them in my template... But it didn't seem to work. Do you know how I can do that ?
Here is what I tried :
{% for annonce in annonces %}
<div class="annonce_item">
{% for photo in annonce.photo %}
<img src="{{ photo.path }}" alt="" />
{% endfor %}
</div>
<!-- End .annonce_item -->
{% endfor %}
annonce is the news class, and photo is the collection :
/**
* @ORM\OneToMany(targetEntity="Photo", mappedBy="id",cascade={"persist"})
*/
private $photo;
When I try to display this page in my browser, I get this exception:
An exception has been thrown during the rendering of a template ("Notice: Undefined index: >id in >/Applications/MAMP/htdocs/ApacheImmobilier/vendor/doctrine/lib/Doctrine/ORM/Persisters/Basi>cEntityPersister.php line 1274") in "APPagesBundle:Index:index.html.twig" at line 45.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读这篇文档。它说:
在您的情况下,它必须是您的照片实体的
news
字段。Read this article of the doc. It says:
which, in your case, must be the
news
field of your Photo entity.