Symfony 3 easyadmin __toString() 不得抛出异常
Symfony 3 easyadmin __toString() must not throw an exception
我正在使用 EasyAdmin 捆绑包。当我尝试在名为 "Company" 的实体中添加一个与 "Service" 实体具有 'ManyToMany' 关系的新元素时,我收到错误消息:
Error: Method AppBundle\Entity\Service::__toString() must not throw an exception
但是当我要在 "Service" 实体中添加一个新元素时,一切正常并且具有 "Company" 个实体的字段显示正确。
我试图捕获实施 this 解决方法的异常,但它没有生效。
服务class:
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;
}
}
和服务 class:
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;
}
}
怎么了?
错误消息非常具体 (Service::__toString() must not throw an exception
),问题一定在 Service
的 $this->name
属性 中。它被定义了吗? "normal" 属性 或某些高级对象在将其转换为字符串时失败了吗?
我正在使用 EasyAdmin 捆绑包。当我尝试在名为 "Company" 的实体中添加一个与 "Service" 实体具有 'ManyToMany' 关系的新元素时,我收到错误消息:
Error: Method AppBundle\Entity\Service::__toString() must not throw an exception
但是当我要在 "Service" 实体中添加一个新元素时,一切正常并且具有 "Company" 个实体的字段显示正确。
我试图捕获实施 this 解决方法的异常,但它没有生效。
服务class:
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;
}
}
和服务 class:
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;
}
}
怎么了?
错误消息非常具体 (Service::__toString() must not throw an exception
),问题一定在 Service
的 $this->name
属性 中。它被定义了吗? "normal" 属性 或某些高级对象在将其转换为字符串时失败了吗?