Symfony2で認識制約の問題があります。私はグループ間の関係を持っています&ロールエンティティ:したがって、グループには必須のロールが必要で、ロールには1つ以上のグループがある場合とない場合があります。したがって、私のaddRoles関数(Groups $ grp)では、グループにロールがあるかどうか毎回チェックしていますので、ロールを割り当てていない場合は、挿入するときしかし、致命的なエラー:symfony 2.7で未定義のメソッドcontains()を呼び出す
私は問題が発生します
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