php - Symfony2 ImageType Form Error

825

I have one entity like this:

class Image
{

/**
 * Identifier
 *
 * @var int
 *
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
protected $id;

/**
 * Image path
 *
 * @var string
 *
 * @ORM\Column(type="string")
 */
protected $path;

/**
 * Image file
 *
 * @var \Symfony\Component\HttpFoundation\File\UploadedFile
 *
 * @Assert\File(maxSize="6000000")
 */
protected $file;

//GETTERS AND SETTERS
}

and other entities have for example:

class User {
  protected $id;

/**
 * Avatar image
 *
 * @var Image
 *
 * @ORM\OneToOne(targetEntity="Vendor\MediaBundle\Entity\Image", cascade={"persist"})
 */
protected $avatar;
//GETTERS AND SETTERS
}

my builder user form Type looks like this:

$builder
        ->add('avatar', new ImageType(), array(
            'required' => false,

        ));

and the ImageType looks like this:

$builder
        ->add('file', 'file', array('required' => false))
        ->add('order', 'hidden');

When I'm not uploading any file I'm receiving this error:

This form should not contain extra fields.

and the parameter is "file"

is driving me crazy...

515

Answer

Solution:

If your are using Symfony2.3, there was a bug in this commit.

Fix has been commited an hour ago.

Update symfony using composer :

./compser.phar update symfony/symfony

Hope this helps

People are also looking for solutions to the problem: html - Sharing session data across domains with PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.