在传递给选择字段的 "Admin\UserBundle\Entity\Extension" 类型的对象上找不到“__toString()”方法

A "__toString()" method was not found on the objects of type "Admin\UserBundle\Entity\Extension" passed to the choice field

然后我安装了 easyAdmin Bundle(symfony2) :

  1. 我把它和 fosUserBundle 结合起来了。
  2. 我添加一个实体"extension"。
  3. 所以我创建了一个用户,但是当我试图在 仪表板我收到此错误:

    A "__toString()" method was not found on the objects of type "Admin\UserBundle\Entity\Extension" passed to the choice field

所以有人可以帮助我吗?

很抱歉提出以下问题,但是添加 __toString() 方法怎么样?

在您的分机中:

public function __toString()
{
    return $this->fieldYouWantToDisplayAsChoice;
}

例如,如果您的分机有 属性 username,您可以使用 return $this->username,选择字段将填充 username 属性 每个用户。

参见 magic __toString