I am trying to take one kind of form and display it, however I need the user to download the patch download at the same time. So say 30 files to download, 30 forms per page. I get this error:
It is expected that data of the form type will be of the scalar, array, or instance \ ArrayAccess types, but this is an instance of the MS \ CoreBundle \ Entity \ Photo class. You can avoid this error by setting the "data_class" option to "MS \ CoreBundle \ Entity \ Photo" or by adding a view transformer that converts an instance of the MS \ CoreBundle \ Entity \ Photo class to a scalar, array, or \ ArrayAccess instance.
Gallery Type Code:
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, )); }
Photo Type Code:
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', )); }
My Controller Function:
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() ); }
Any help would be great.
php symfony symfony-forms
Dave mascia
source share