Answer the question
In order to leave comments, you need to log in
Why is the entity update form not working?
Symfony 4.0
Entity:
https://pastebin.com/V7amJQED
Form:
<?php
namespace App\Form\Dashboard\Book;
use App\Entity\Book;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class BookEditType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('cover', FileType::class)
->add('slug', TextType::class)
->add('name', TextType::class)
->add('description', TextareaType::class)
->add('plot', TextareaType::class)
->add('published_at', DateType::class, [
'years' => range(date('Y') - 25, date('Y')),
])
->add('save', SubmitType::class);
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Book::class,
]);
}
}
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Symfony\Component\HttpFoundation\File\File.
$resolver->setDefaults([
'data_class' => null,
]);
Cannot read index "cover" from object of type "App\Entity\Book" because it doesn't implement \ArrayAccess.
Answer the question
In order to leave comments, you need to log in
It means to set data_class for the cover field. Have a look here: https://github.com/symfony/symfony/blob/833909bd68...
See, data_class is set to Symfony\Component\HttpFoundation\File\File
Try this:
UPD: And in general, you are doing the download incorrectly. See here https://symfony.com/doc/current/controller/upload_...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question