VichUploaderBundle - namer:父定义不存在

时间:2018-01-25 11:13:37

标签: symfony symfony-3.3 vichuploaderbundle

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

实体:

/**
 * 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;

当我启用namer时,我收到此错误:

enter image description here

任何想法为什么?

1 个答案:

答案 0 :(得分:9)

(custom-)名称应该注册为服务,并由服务名称引用。

您可以在下面的示例中看到默认(长)配置以及VichUploaderBundle提供的名称服务列表:

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

供参考,以下是命令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