Vichuploaderbundle: Dont find mapping ,Mapping not found for field

Created on 15 Sep 2017  路  6Comments  路  Source: 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

Entitity

<?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")
     *
     * @var File
     */
    private $imageFile;

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

    /**
     * @ORM\Column(type="datetime")
     *
     * @var \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.
     *
     * @param 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();
        }
    }

    /**
     * @return File|null
     */
    public function getImageFile()
    {
        return $this->imageFile;
    }

    /**
     * @param EmbeddedFile $image
     */
    public function setImage(EmbeddedFile $image)
    {
        $this->image = $image;
    }

    /**
     * @return EmbeddedFile
     */
    public function getImage()
    {
        return $this->image;
    }


}

I dont understand why dont find the mapping I need help please

Support

Most helpful comment

For anyone coming here with the same error:

In your form you must use the $imageFile property instead of the $image one.

All 6 comments

I cant mix a normal entity with this ??? I need only a entity for pictures ?

Solve I find the problem in the form

For anyone coming here with the same error:

In your form you must use the $imageFile property instead of the $image one.

@diegocastro
I'm experiencing the same issue
What is the exact solution ? I am using easyAdminBundle.

Thanks

@stef59100 I don't use the EasyAdminBundle so I can't help you there. Is there any place where you define a form? If so don't map the form to the $image property, use the $imageFile instead.

I experienced the same issue as @diegocastro, with EA, however the problem was unrelated : I just forgot the @Vich\Uploadable annotation at the top of my entity file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fleskalebas picture fleskalebas  路  6Comments

petrjirasek picture petrjirasek  路  7Comments

smilesrg picture smilesrg  路  6Comments

seddighi78 picture seddighi78  路  4Comments

andrea-daru picture andrea-daru  路  3Comments