VichUploaderBundle - namer: Parent definition does not exist

不羁的心 提交于 2021-01-27 04:42:18

问题


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:

Any ideas why?


回答1:


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


来源:https://stackoverflow.com/questions/48441537/vichuploaderbundle-namer-parent-definition-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!