VichUploaderBundle - namer: Parent definition does not exist
Asked Answered
V

1

7

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?

Venial answered 25/1, 2018 at 11:13 Comment(2)
Did you register Vich\UploaderBundle\Naming\OrignameNamer as a service? If yes - add the service definition to the question please.Satirize
Oh nevermind you're using one of the default namers :) See my answer for the solution.Satirize
H
14

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
Humes answered 25/1, 2018 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.