2013-06-12 37 views
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; 
    } 
+1

请显示你的SplurginE ventPackagesType'形式。 –

+0

@forgottenbas我已更新帖子 –

+1

第317行前后的C:\ wamp \ www \ new \ src \ Splurgin \ EventsBundle \ Entity \ SplurginEventEvents.php中有什么? –

回答

0

很多的(我的意思是很多)的头发经过这么拉这就是问题所在

在封装类型

public function setDefaultOptions(OptionsResolverInterface $options) 
{ 
    return array(
     'data_class' => 'Splurgin\EventsBundle\Entity\SplurginEventPackages', 
    ); 
} 

应该

public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'Splurgin\EventsBundle\Entity\SplurginEventPackages', 
    )); 
} 

这会听起来很蠢,但我想我需要睡一觉,呵呵

相关问题