Sonata AdminBundle with a Child 无法渲染


Sonata AdminBundle with a Child cannot be rendered

我正在尝试配置Sonata AdminBundle。这是一个非常有趣的捆绑包,具有许多功能,但是使用起来并不简单。我有一个帖子实体,所以我可以调整帖子,就像在文档手册中一样。我想实现一个子管理员,用于每个帖子的评论(多对一关系)。我将其实现为变量的服务和 __toString() 方法,但是出现以下错误:

呈现

模板期间引发异常 ("可捕获的致命错误:类的对象 Doctrine''ORM''PersistentCollection 无法转换为字符串") in SonataDoctrineORMAdminBundle:CRUD:list_orm_many_to_one.html.twig at 第 17 行。

我不明白为什么不能将 ManyToOne 变量的内容转换为字符串。这里感谢任何帮助。

以下是发布实体代码:

<?php
namespace Blog'BlogBundle'Entity;
class Post
/**
 * @var ArrayCollection
 *
 * @ORM'OneToMany(targetEntity="Comment", mappedBy="post", cascade={"remove"})
 */
private $comments;
/**
* Construct DateTime and Comments Array
*/
public function __construct()
{
    $this->createdAt = new 'DateTime();
    $this->comments = new ArrayCollection();
}
/**
 * @return mixed
 */
public function __toString()
{
    return $this->comments;
}
Other private and setters and getters

删除

/**
 * @return mixed
 */
public function __toString()
{
    return $this->comments;
}
,并将其

添加到评论实体,但将$this>注释更改为用于评论正文的字段。

IMO :

/**
 * @return mixed
 */
 public function __toString()
 {
     return $this->comments;
 }

此方法必须返回字符串而不是数组集合