Ich versuche, einen Formulartyp zu nehmen und es anzuzeigen, aber ich benötige, dass der Benutzer einen Patch-Upload auf einmal hochlädt. Sagen Sie also 30 Dateien hochgeladen, 30 Formulare auf der Seite. Ich erhalte diese Fehlermeldung:Formularauflistungsfehler
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class MS\CoreBundle\Entity\Photo. You can avoid this error by setting the "data_class" option to "MS\CoreBundle\Entity\Photo" or by adding a view transformer that transforms an instance of class MS\CoreBundle\Entity\Photo to scalar, array or an instance of \ArrayAccess.
Die Galerie Art-Code ist:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('photo', 'collection', array(
'type' => new PhotoType(),
'allow_add' => true,
'data_class' => 'MS\CoreBundle\Entity\Photo',
'prototype' => true,
'by_reference' => false,
));
}
Der Foto-Typ-Code ist:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', 'text', array('label' => "Title:", 'required' => true))
->add('File')
->add('album', 'entity', array(
'class' => 'MSCoreBundle:Album',
'property' => 'title',
'required' => true,
'query_builder' => function(EntityRepository $er)
{
return $er->createQueryBuilder('a')
->orderBy('a.title', 'ASC');
},
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MS\CoreBundle\Entity\Photo',
));
}
Meine Reglerfunktion ist:
public function newAction($count)
{
for($i = 1; $i <= $count; $i++) {
$entity = new Photo();
}
$form = $this->container->get('ms_core.gallery.form');
$form->setData($entity);
return array(
'entity' => $entity,
'form' => $form->createView()
);
}
Jede Hilfe wäre großartig.