0
即時嘗試持續收集表單... 奇怪的是,代碼在2.0上工作,但不在2.2(我是我的錯,但我很確定它是)當持久層疊時調用非對象的成員函數
這裏是代碼的我的表格類型的相關部分..
錯誤
Error: Call to a member function setEventId() on a non-object in C:\wamp\www\new\src\Splurgin\EventsBundle\Entity\SplurginEventEvents.php line 317
->add('packages' , 'collection', array('type'=>new SplurginEventPackagesType(),
'allow_add' => true,
'by_reference' => false,
))
個
我的事件實體錯誤所在
/**
* @ORM\OneToMany(targetEntity="Splurgin\EventsBundle\Entity\SplurginEventPackages", mappedBy="eventId" ,cascade={"persist"})
*/
private $packages;
public function __construct()
{
$this->media = new \Doctrine\Common\Collections\ArrayCollection();
$this->packages = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getPackages()
{
return $this->packages;
}
public function setPackages($packages)
{
$this->packages = $packages ?: new \Doctrine\Common\Collections\ArrayCollection();
foreach ($this->packages as $package) {
$package->setEventId($this); // line of error
}
return $this->packages;
}
我的包實體
/**
* @var integer $eventId
* @ORM\ManyToOne(targetEntity="SplurginEventEvents", inversedBy="packages")
* @ORM\JoinColumn(name="event_id", referencedColumnName="id")
*/
private $eventId;
/**
* Set eventId
*
* @param integer $eventId
*/
public function setEventId(\Splurgin\EventsBundle\Entity\SplurginEventEvents $eventId)
{
$this->eventId = $eventId;
}
/**
* Get eventId
*
* @return integer
*/
public function getEventId()
{
return $this->eventId;
}
包在我的控制器類型
class SplurginEventPackagesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('price')
->add('description')
->add('items')
;
}
public function setDefaultOptions(OptionsResolverInterface $options)
{
return array(
'data_class' => 'Splurgin\EventsBundle\Entity\SplurginEventPackages',
);
}
public function getName()
{
return 'packages';
}
}
沒有什麼有趣的只是檢查,如果形式是有效並堅持它。
更新:我已經更新了js文件
The placeholder was changed from $$name$$ to __name__ in Symfony 2.1
UPDATE2:看來,我需要添加,添加和刪除功能..但林不知道,雖然
更新3:添加附加並刪除方法(雖然在文檔中),但我仍然得到相同的錯誤,但在添加方法
這裏是添加方法的代碼,並且唯一已更改的代碼是setPackages方法
public function getPackages()
{
return $this->packages;
}
public function addPackage(ArrayCollection $package) // if i put the type hinting i get an error that array collection was not passed , i get a normal array instead
{
$package->setEventId($this); // this thoughs an error (because we cant use set event method on an array
$this->packages->add($package);
}
public function removePackage(ArrayCollection $package)
{
//...
}
public function setPackages($packages)
{
$this->packages = $packages ;
return $this->packages;
}
請顯示你的SplurginE ventPackagesType'形式。 –
@forgottenbas我已更新帖子 –
第317行前後的C:\ wamp \ www \ new \ src \ Splurgin \ EventsBundle \ Entity \ SplurginEventEvents.php中有什麼? –