我正在使用EasyAdmin Bundle。当我试图在名为"公司"的实体中添加新元素时其中有很多很多人。与"服务"的关系实体我收到错误:
Error: Method AppBundle\Entity\Service::__toString() must not throw an exception
但是当我要在" Service"中添加新元素时实体,一切正常,与#34;公司"实体正确显示。
我试图抓住实施this解决方法的异常,但它没有生效。
服务类:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Company
*
* @ORM\Table(name="company")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CompanyRepository")
*/
class Company
{
/**
* @var
*
* Many Companys have Many Services.
* @ORM\ManyToMany(targetEntity="Service", inversedBy="companys")
* @ORM\JoinTable(name="companys_services")
*/
private $services;
public function __construct() {
$this->services = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
}
服务类:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Service
*
* @ORM\Table(name="service")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ServiceRepository")
*/
class Service
{
/**
* Many Services have Many Companys.
* @ORM\ManyToMany(targetEntity="Company", mappedBy="services")
*/
private $companys;
public function __construct()
{
$this->companys = new ArrayCollection();
}
public function __toString()
{
return (string) $this->name;
}
}
有什么问题?
答案 0 :(得分:0)
错误消息非常具体(Service::__toString() must not throw an exception
),问题必须位于$this->name
的{{1}}属性中。它定义了吗?是“普通”属性还是某些高级对象在将其转换为字符串时失败?