gpt4 book ai didi

doctrine - 用 Twig 展示 Doctrine 集? (Symfony2)

转载 作者:行者123 更新时间:2023-12-02 20:05:51 29 4
gpt4 key购买 nike

我有一个非常简单的代表新闻的 Doctrine 实体;这个新闻可以与很多图片联系起来,所以我决定使用 Doctrine 集。问题是,我想检索这些图片并将它们显示在我的模板中......但它似乎不起作用。你知道我该怎么做吗?

这是我尝试过的:

{% 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;

当我尝试在浏览器中显示此页面时,出现以下异常:

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.

谢谢!

最佳答案

阅读this article of the doc 。它说:

The mappedBy attribute designates the field in the entity that is the owner of the relationship.

在您的情况下,它必须是您的照片实体的 news 字段。

关于doctrine - 用 Twig 展示 Doctrine 集? (Symfony2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8287657/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com