Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VichUploaderBundle - namer: Parent definition does not exist

config.yml

vich_uploader:
    db_driver: orm
    mappings:
        media_image:
            uri_prefix:         '%uploads_dir%'
            upload_destination: '%kernel.root_dir%/../web/uploads/images'
            namer: Vich\UploaderBundle\Naming\OrignameNamer

Entity:

/**
 * Media
 * @Vich\Uploadable
 * @ORM\Table(name="medias")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\MediaRepository")
 */
class Media
{

    use TimestampableEntity;

    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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

    /**
     * @Vich\UploadableField(mapping="media_image", fileNameProperty="imageName", mimeType="mimeType", size="size")
     * @var File
     */
    private $imageFile;

    /**
     * @var string
     *
     * @ORM\Column(name="mime_type", type="string", length=20, nullable=true)
     */
    private $mimeType;

    /**
     * @var string
     *
     * @ORM\Column(name="size", type="integer", nullable=true)
     */
    private $size;

When I enable namer, I am getting this error:

enter image description here

Any ideas why?

like image 727
breq Avatar asked Jan 25 '18 11:01

breq


Video Answer


1 Answers

The (custom-)namer should be registered as a service and referred to by its service name.

You can see the default (long) configuration together with a list of namer services provided by VichUploaderBundle in the example below:

vich_uploader:   
  # [..]
  mappings:
    product_image_file:
      # [..]
      namer:
        # one of: vich_uploader.namer_{uniqid,origname,property,hash}
        service: vich_uploader.namer_origname

For reference, here are all namer services as listed by the command bin/console debug:container:

vich_uploader.namer_base64                Vich\UploaderBundle\Naming\Base64Namer
vich_uploader.namer_directory_property    Vich\UploaderBundle\Naming\PropertyDirectoryNamer
vich_uploader.namer_hash                  Vich\UploaderBundle\Naming\HashNamer
vich_uploader.namer_origname              Vich\UploaderBundle\Naming\OrignameNamer
vich_uploader.namer_property              Vich\UploaderBundle\Naming\PropertyNamer
vich_uploader.namer_uniqid                Vich\UploaderBundle\Naming\niqidNamer
like image 65
Nicolai Fröhlich Avatar answered Sep 28 '22 05:09

Nicolai Fröhlich