이것은 이상합니다. 다른 관련 엔터티의 ArrayCollection을 포함 할 수있는 엔터티가 있습니다. 단일 엔티티의 값을 추가/검색 할 수 있도록 몇 가지 도우미 메서드를 만들면 메서드가 정의되지 않았다는 Symfony2 예외가 발생합니다. 네임 스페이스를 포함하므로 문제가 무엇인지 알 수 없습니다. 이처럼 보이는,Symfony2 - Doctrine ArrayCollection 메서드가 정의되지 않은 상태로 되돌려졌습니다
FatalErrorException: Error: Call to undefined method Acme\MyBundle\Entity\Thing::current() in /home/kevin/www/project/vendor/acme/my-bundle/Acme/MyBundle/Entity/MyEntity.php line 106
오류에 의해 판단 : 정말로 이상한 것은이 current()
에서 예외를 던지는하지만 add()
점이다
namespace Acme\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
// ...
public function setThing($thing)
{
$this->things->add($thing);
}
public function getThing()
{
return $this->things->current();
}
: 코드 아래 (이름 때문에 NDA에 약간 변경) things
을 ArrayCollection으로 취급하지 않습니다. things
을 ArrayCollection으로 강제 설정할 수 있습니까? 나는 다음과 같은 것을 이미 가지고있다 :
/**
* @var ArrayCollection things
*
* @ORM\OneToMany(targetEntity="Thing", mappedBy="other")
*/
private $things;
그러나 나는 무엇을 해야할지 잘 모르겠다.
당신이 당신의'Thing' 클래스의 메소드'add'이 있습니까 대신
ArrayCollection
null
있어? – bpoiss'getThing()'을 호출하기 전에 객체를'var_dump()'할 수 있습니까? – cheesemacfly
아니요. 다시 말하지만, '물건들'이 그 시점에서 컬렉션이되어야한다고 '잊어 버린'것처럼 보입니다. –