我搜索了一段时间,但直到现在,我还没有找到合适的答案。
在我的"优惠"上课时,我有以下几点:
/**
* @ORM\OneToMany(mappedBy="offer")
* @var Collection<OfferItem>
*/
protected $offerItems;
/**
* @return Collection
*/
public function getOfferItems()
{
return $this->offerItems;
}
/**
* @param Collection $offerItems
*/
public function setOfferItems($offerItems)
{
$this->offerItems = $offerItems;
}
现在,我创建了一个新的商品,并希望添加一些OfferItems:
$offer = new Offer();
$offerItem = new OfferItem();
$offer->getOfferItems()->add($offerItem);
然后,错误来了:&#34;致命错误:在null&#34;上调用成员函数add()。好吧,在某些方面,它是有道理的 - 收集是空的,直到知道 - 也许&#34; null&#34;。 我不是这样的PHP / Flow3 / Doctrine专家,有了概述,如何处理这样的引用? 我想,我必须在商品中设置一个空的(但不是空的)集合。但是
$collection = new \Doctrine\Common\Collections\Collection()
不工作,因为&#34;收集&#34;是一个界面。
任何暗示,想法或类似的东西,以理解我的问题都会很好。
非常感谢您的帮助!