Created
January 16, 2019 22:30
-
-
Save ismail1432/f7f7a1dfeb8171d6fadae5dc962fe406 to your computer and use it in GitHub Desktop.
"Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/Form/EditUserType.php | |
class EditUserType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('email', EmailType::class) | |
->add('password', RepeatedType::class, [ | |
'type' => PasswordType::class, | |
'invalid_message' => 'Les mots de passes doivent être identiques !', | |
'required' => true, | |
'first_options' => ['label' => 'Mot de passe'], | |
'second_options' => ['label' => 'Répeter le mot de passe'], | |
]) | |
->add('image', ImageType::class) | |
->add('Inscription', SubmitType::class) | |
; | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults([ | |
'data_class' => User::class, | |
'path' => null, | |
]); | |
} | |
} | |
// src/Form/ImageType | |
class ImageType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('file', FileType::class, ['label' => false]) | |
; | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults([ | |
'data_class' => Image::class, | |
]); | |
} | |
} | |
// src/Entity/Image | |
class Image implements \Serializable | |
{ | |
// Update attributes with yours | |
public function serialize() | |
{ | |
return serialize(array( | |
$this->id, | |
$this->path, | |
$this->name | |
)); | |
} | |
public function unserialize($serialized) | |
{ | |
list ( | |
$this->id, | |
$this->path, | |
$this->name | |
) = unserialize($serialized); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment