2013-05-30 58 views
0

我有表單集合的問題。我得到一個錯誤:Symfony表單集合flush()錯誤

Notice: Array to string conversion in /home/.../vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 103 

我想的foreach(像是主義文檔中)和perist每個對象,但我得到一個錯誤:

The class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces FOS\UserBundle\Entity, Ix\UserBundle\Entity, Ix\x\Entity, FOS\UserBundle\Model 

下面是我的代碼:

實體:

/** 
* @ORM\Entity 
* @ORM\Table(name="availability") 
*/ 

class Availability 
{ 
    public function __construct() 
    { 
     $this->availabilityFlexible = new \Doctrine\Common\Collections\ArrayCollection(); 
     $this->availabilitySession = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 


    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(name="description", type="string", length=255, nullable=true) 
    */ 
    protected $description; 

    /** 
    * @ORM\OneToMany(targetEntity="AvailabilityFlexible", mappedBy="availability", cascade={"persist", "remove"}) 
    */ 
    protected $availabilityFlexible; 

    /** 
    * @ORM\OneToOne(targetEntity="AvailabilityFull", mappedBy="availability", cascade={"persist", "remove"}) 
    */ 
    protected $availabilityFull; 

    /** 
    * @ORM\OneToMany(targetEntity="AvailabilitySession", mappedBy="availability", cascade={"persist", "remove"}) 
    */ 
    protected $availabilitySession; 

    // AvailabilityFlexible.php 
    /** 
    * @ORM\ManyToOne(targetEntity="Availability", inversedBy="availabilityFlexible", cascade={"persist"}) 
    * @ORM\JoinColumn(name="availability_id", referencedColumnName="id") 
    */ 
    protected $availability; 


    // AvailabilityFull.php 
    /** 
    * @ORM\OneToOne(targetEntity="Availability", inversedBy="availabilityFull", cascade={"persist"}) 
    * @ORM\JoinColumn(name="availability_id", referencedColumnName="id") 
    */ 
    protected $availability; 



    // AvailabilitySession.php 
    /** 
    * @ORM\ManyToOne(targetEntity="Availability", inversedBy="availabilitySession", cascade={"persist"}) 
    * @ORM\JoinColumn(name="availability_id", referencedColumnName="id") 
    */ 
    protected $availability; 

形式:

public function buildForm(FormBuilderInterface $builder, array $options) 
    { 

    $builder->add('description') 
      ->add('AvailabilitySession', 'collection', array(
       'type' => new AvailabilitySessionFormType(), 
       'allow_add' => true, 
       'prototype' => true, 
       'by_reference' => false, 
       'allow_delete' => true, 
      )) 
      ->add('AvailabilityFull', new AvailabilityFullFormType()) 
      ->add('AvailabilityFlexible', 'collection', array(
       'type' => new AvailabilityFlexibleFormType(), 
       'allow_add' => true, 
       'by_reference' => false, 
       'allow_delete' => true, 
    )); 
} 

控制器:

public function addAvailabilityAction(Request $request) 
{ 
    $availability = new Availability; 
    $availability->getAvailabilityFlexible()->add(new AvailabilityFlexible); 
    $availability->getAvailabilityFlexible()->add(new AvailabilityFlexible); 

    $form = $this->createForm(new AvailabilityFormType(), $availability); 

    if ($request->isMethod('POST')) { 
     $form->bind($request); 
     if ($form->isValid()) { 
      $availability = $form->getData(); 
      $em = $this->getDoctrine()->getManager(); 
      $em->perist($availability); 
      $em->flush(); 
     } 
    } 
} 
+0

你不能在一個類的同一個屬性中使用PHP多次!你有3次可用性,你有沒有例外PHP xD? – Sybio

回答

0

屬性$可用性是在不同的班級。

  1. AvailabilityFlexible.php
  2. AvailabilityFull.php
  3. AvailabilitySession.php

這是可用性實體的關係。