Vichuploaderbundle: Não encontrar mapeamento, mapeamento não encontrado para o campo

Criado em 15 set. 2017  ·  6Comentários  ·  Fonte: dustin10/VichUploaderBundle

config.yml 
vich_uploader:
    db_driver: orm
    mappings:
        team_image:
            uri_prefix:         /uploads/logos
            upload_destination: '%kernel.root_dir%/../web/uploads/logos'
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true

Entidade

<?php


namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;



/**
 * @ORM\Entity
 * @Vich\Uploadable
 * @ORM\Table(name="team")
 */
class Team
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    // ..... other fields

    /**
     * NOTE: This is not a mapped field of entity metadata, just a simple property.
     *
     * @Vich\UploadableField(mapping="team_image", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName")
     *
     * <strong i="8">@var</strong> File
     */
    private $imageFile;

    /**
     * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
     *
     * <strong i="9">@var</strong> EmbeddedFile
     */
    private $image;

    /**
     * @ORM\Column(type="datetime")
     *
     * <strong i="10">@var</strong> \DateTime
     */
    private $updatedAt;

    /**
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
     * of 'UploadedFile' is injected into this setter to trigger the  update. If this
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
     * must be able to accept an instance of 'File' as the bundle will inject one here
     * during Doctrine hydration.
     *
     * <strong i="11">@param</strong> File|UploadedFile $image
     */
    public function setImageFile(File $image = null)
    {
        $this->imageFile = $image;

        if ($image) {
            // 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
            $this->updatedAt = new \DateTimeImmutable();
        }
    }

    /**
     * <strong i="12">@return</strong> File|null
     */
    public function getImageFile()
    {
        return $this->imageFile;
    }

    /**
     * <strong i="13">@param</strong> EmbeddedFile $image
     */
    public function setImage(EmbeddedFile $image)
    {
        $this->image = $image;
    }

    /**
     * <strong i="14">@return</strong> EmbeddedFile
     */
    public function getImage()
    {
        return $this->image;
    }


}

Eu não entendo porque não encontro o mapeamento Eu preciso de ajuda por favor

Support

Comentários muito úteis

Para quem vem aqui com o mesmo erro:

Em seu formulário, você deve usar a propriedade $imageFile em vez de $image one.

Todos 6 comentários

Não consigo misturar uma entidade normal com isso ??? Preciso apenas de uma entidade para fotos?

Resolver Encontro o problema no formulário

Para quem vem aqui com o mesmo erro:

Em seu formulário, você deve usar a propriedade $imageFile em vez de $image one.

@diegocastro
Estou tendo o mesmo problema
Qual é a solução exata? Estou usando o easyAdminBundle.

Obrigado

@ stef59100 Não uso o EasyAdminBundle, então não posso ajudá-lo. Existe algum lugar onde você define um formulário? Se sim, não mapeie o formulário para a propriedade $image , use $imageFile vez disso.

Tive o mesmo problema que @diegocastro , com a EA, mas o problema não estava relacionado: apenas esqueci a anotação @Vich\Uploadable no topo do meu arquivo de entidade.

Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

webkmua picture webkmua  ·  4Comentários

Propscode picture Propscode  ·  4Comentários

manguecreative picture manguecreative  ·  4Comentários

Chrysweel picture Chrysweel  ·  4Comentários

seddighi78 picture seddighi78  ·  4Comentários