Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:53:21+00:00 2026-06-06T11:53:21+00:00

I am trying to take one form type and display it however times i

  • 0

I am trying to take one form type and display it however times i need for the user to upload a patch upload at one time. So say 30 files to uploaded, 30 forms on the page. I am receiving this error:

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.

The Gallery Type code is:

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,
    ));
}

The Photo Type code is:

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 is:

     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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:53:23+00:00Added an answer on June 6, 2026 at 11:53 am

    You should not pass the data_class option to the collection type in your GalleryType. Or, if you do want to override the PhotoType’s default (which is already set, so you shouldn’t have to), you can specify it in the options array like so:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('photo', 'collection', array(
            'type' => new PhotoType(),
            'allow_add' => true,
            'options' => array('data_class' => 'MS\CoreBundle\Entity\Photo'),
            'prototype' => true,
            'by_reference' => false,
        ));
    }
    

    Make sure you do have a default data_class option set in your “GalleryType”, it should be an Album, it seems.

    Also, in your controller you are not creating the form correctly. You need to call setData() with the data type of the form, in this case an Album.

    public function newAction($count)
    {
            $album = new Album();
            for($i = 1; $i <= $count; $i++) {
                $album->addPhoto(new Photo());
            }
    
            $form = $this->container->get('ms_core.gallery.form');
            $form->setData($album);
    
            return array(
                'entity' => $album,
                'form' => $form->createView()
            );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to take one group and put it in two different columns. I
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
I am trying to take the user to login page after cookies are cleared.
Has anyone used jquery to take data from one form field and put it
Has anyone used javascript/ajax to take data from one form field and put it
I'm trying to get my head around this one: Say you have two models
I am trying to use inheritance to pass a string from one form to
I am having a hard time trying to figure out what I need to
I am trying to take a two text areas with multiple emails, one with
I have a datagridview with 9 columns. I am simply trying take the value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.