【发布时间】:2016-01-03 23:41:13
【问题描述】:
我正在尝试使用 Twig 模板在博客上使用 Symfony 和 Doctrine 实现评论部分。
我在尝试为我的 cmets 实施响应系统时遇到了一些麻烦。我想要这样的东西:
<div class="comment">
<p>This is comment number 1</p>
<div class="response">
<p>This is a response to comment number 1</p>
<div class="response">
<p>This is a response to response just above</p>
</div>
</div>
</div>
所以我想要一个嵌套的评论系统。
我有一个带有 $response 属性的 Comment 实体,该属性与另一个 Comment 实体具有 OneToOne 关系:
/**
* @ORM\OneToOne(targetEntity="Comment")
*/
protected $response;
在我的控制器中,我的 cmets 是这样的:
$comments = $this->getDoctrine()
->getManager()
->getRepository('AppBundle:Comment')
->findByArticle($article);
现在我正在尝试创建 HTML (Twig),但我不知道如何遍历所有评论和相关响应,因此我可以创建上面写的 HTML...
谁能帮我解决这个问题?
谢谢。
【问题讨论】:
标签: php doctrine-orm twig symfony