Symfony2中有一個識別constrains()方法的問題。我有一個組之間的關係&角色實體:所以一個組必須有一個強制角色,角色可能有或可能沒有一個或多個組。因此,在我的addRoles函數(Groups $ grp)中,我已經檢查過每次該組是否有角色,因此如果不分配角色,我們就會進行比較。但插入時,致命錯誤:調用未定義的方法在Symfony 2.7中包含()
我遇到一個問題:
PHP Fatal error: Call to undefined method MemberShipManagement\GroupsBundle\Entity\Roles::contains() in /var/www/Project_Console/src/MemberShipManagement/GroupsBundle/Entity/Roles.php on line 118,
類羣:
/**
* @var Roles $role
*
* @ORM\ManyToOne(targetEntity="Roles", inversedBy="groups")
* @ORM\JoinColumn(name="role_id", referencedColumnName="id", nullable=false)
*
* @Assert\Valid()
*/
protected $role;
類角色:
/**
* @var ArrayCollection $groups
*
* @ORM\OneToMany(targetEntity="Groups", mappedBy="role", cascade={"remove"})
*@Assert\Valid()
*/
protected $groups;
/**
* Add group
* @param Groups $grp
*/
public function addRoles(Groups $grp) {
// $grp->setRole($this);
if (!$this->groups->contains($grp)) {
$this->groups->add($grp);
}
return $this;
}
/**
* Remove groups
* @param Groups $groups
*/
public function removeRoles(Groups $groups)
{
if ($this->groups->contains($groups)) {
$this->groups->removeElement($groups);
}
return $this;
}
public function __construct()
{
$this->groups = new ArrayCollection();
}
謝謝:)
非常感謝您的先生:) – Cros