我有表单收集的问题。我收到一个错误:
Notice: Array to string conversion in /home/.../vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 103
我尝试了foreach(就像在doctrine文档中一样)并且每个对象都存在,但是我收到了一个错误:
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 :(得分:0)
属性$ availability在不同的类中。
这是与可用实体的关系。