Symfony FileType:class does not work when trying to update

Hi everyone I have a question! How I can solve this problem:

the form’s view data is expected to be an instance of class
SymfonyComponentHttpFoundationFileFile, but is a(n) resource. You
can avoid this error by setting the “data_class” option to null or by
adding a view transformer that transforms a(n) resource to an
instance of SymfonyComponentHttpFoundationFileFile.

This error happens when I try to update it but it doesn’t work with the FileType::class

this is my code:

<?php
    namespace XInteractiveBundleLeadsBundleForm;


    use SymfonyComponentFormExtensionCoreTypeFileType;
    use SymfonyComponentFormAbstractType;
    use SymfonyComponentFormFormBuilderInterface;
    use SymfonyComponentOptionsResolverOptionsResolver;
    use XInteractiveBundleLeadsBundleEntityDocument;

    class DocumentType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
            ->add('name', null)
            ->add('file', FileType::class);

        }

        public function configureOptions(OptionsResolver $resolver)
        {
            $resolver->setDefaults([
                'data_class' => Document::class
            ]);
        }
    }

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *