ERREUR SEMANTIQUE SYMFONY ANNOTATION

Par SEDI, il y a 4 ans


Bonjour jai essayé de cree des mixture via php bin/console make:migration
et il m'affiche ca

php bin/console make:migration In AnnotationException.php line 39: [Semantical Error] The annotation "@Vich\UploaderBundle\Mapping\Annotati on" in class App\Entity\Article was never imported. Did you maybe forget to add a "use" statement for this annotation? make:migration

pourtant avant de les lancer jai mis ces "use"

<?php namespace App\Entity; use App\Repository\ArticleRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\HttpFoundation\File\File; use Vich\UploaderBundle\Mapping\Annotation as Vich; use Symfony\Component\HttpFoundation\File\UploadedFile;

Pouvez vous m'expliquez l'erreur svp

est ce que mes mixtures ont été créer ?

MERCI

4 réponses

Corail Dos Santos, il y a 4 ans

use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation\UploadableField;

/**

  • @Vich\Uploadable
  • @ORM\Entity(repositoryClass=ArticleRepository::class)
    */
    class Article
    {

    Ajoute cette annotation dans ton entité

silone, il y a 4 ans

tu dois avoir oublier d'ajouter un mapping sur ton attribut articleFile

SEDI, il y a 4 ans

jai mis les "use" que tu m'as envoyé

``<?php

namespace App\Entity;

use App\Repository\ArticleRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
use Vich\UploaderBundle\Mapping\Annotation\UploadableField;

/**

  • @ORM\Entity(repositoryClass=ArticleRepository::class)
  • @Vich/Uploadable
    */
    class Article
    {

Mais lorsque je vais sur mon localhost:8000 ca me met l'erreur semantique suivante

[Semantical Error] The annotation "@Vich\UploaderBundle\Mapping\Annotation" in class App\Entity\Article was never imported. Did you maybe forget to add a "use" statement for this annotation?

je ne comprend pas aidez moi svp

Arbi, il y a 4 ans

Verifier bien si la class Vich\UploaderBundle\Mapping\Annotation existe bien dans le dossier vendor

puis voici un exemple d'utilisation

use Symfony\Component\HttpFoundation\File\File; use Vich\UploaderBundle\Mapping\Annotation as Vich; /** * @ORM\Entity * @Vich\Uploadable */ class Product { /** * @ORM\Column(type="string", length=255) * @var string */ private $image; /** * @Vich\UploadableField(mapping="product_images", fileNameProperty="image") * @var File */ private $imageFile; /** * @ORM\Column(type="datetime") * @var \DateTime */ private $updatedAt; // ... public function setImageFile(File $image = null) { $this->imageFile = $image; // VERY IMPORTANT: // It is required that at least one field changes if you are using Doctrine, // otherwise the event listeners won't be called and the file is lost if ($image) { // if 'updatedAt' is not defined in your entity, use another property $this->updatedAt = new \DateTime('now'); } } public function getImageFile() { return $this->imageFile; } public function setImage($image) { $this->image = $image; } public function getImage() { return $this->image; } }