ERROR Typed property App\Entity::$file must not be accessed before initi

Signaler
Messages postés
39
Date d'inscription
mardi 2 février 2021
Statut
Membre
Dernière intervention
9 juin 2021
-
Bonjour, depuis hier je cherche la solution à cette erreur ! voici mon buildForm ( ouj 'ai tenté d'ajouter un mapped à false et un data_class à null (selon conseil) mais non !
class PictureType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('file', FileType::class, [
                'required' => false,
                'label' => 'Fichier',
            ])
            ->add(
                'subtitle',
                TextType::class,
                [
                    'label' => 'Sous-titre',
                ]
            );
    }

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


et mon entity concerné :
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Repository\PictureRepository;
use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
 * @ORM\Entity(repositoryClass=PictureRepository::class)
 */
class Picture
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $subtitle;

    /**
     * @var UploadedFile|null
     */
    private ?UploadedFile $file;


    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getSubtitle(): ?string
    {
        return $this->subtitle;
    }

    public function setSubtitle(?string $subtitle): self
    {
        $this->subtitle = $subtitle;

        return $this;
    }
    public function __toString()
    {
        return $this->getName();
    }
    /**
     * @param UploadedFile|null $file
     * @return $this
     */
    public function setFile(?UploadedFile $file): self
    {
        $this->file = $file;

        return $this;
    }
    /**
     * @return UploadedFile|null
     */

    public function getFile(): ?UploadedFile
    {
        return $this->file;
    }
}


certains parlent d'un beug d'autres le lecture de string!! bref je trouve pas ! auriez vous deja vu ce souci? merci bien bonne journee