如何在yml映射的实体中配置VichUploader? [英] How to configure VichUploader in entity mapped by yml?

查看:127
本文介绍了如何在yml映射的实体中配置VichUploader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为杂志"的实体,该实体是从yml文件映射的:

I have a entity called 'Magazine', mapped from yml file:

Acme\DemoBundle\Entity\Magazine:
  type: entity
  table: magazine
  id:
    id:
      type: integer
      generator: { strategy: AUTO }

  fields:
    edition:
        type: string
        length: 255
        nullable: false
    title:
        type: text
        nullable: false
    cover:
        type: string
        length: 255
        nullable: false
    file:
        mapping: magazine_cover
        filename_property: cover

我在app/config/config.yml中进行了必要的配置:

I made the configuration necessary in the app/config/config.yml:

knp_gaufrette:
  stream_wrapper: ~

vich_uploader:
  db_driver: orm
  mappings:
    magazine_cover:
      uri_prefix:         /upload/magazine/cover
      upload_destination: %kernel.root_dir%/../web/upload/magazine/cover
      delete_on_remove:   true

实体文件:

use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\PropertyMapping as Vich;

我不是这样工作的,在"magazine"表中创建了一个"file"字段,这种情况不应该发生.我发现一些文章解释了如何使用注释进行配置,但是yml我什么也没发现.

I'm not getting work this way, a field 'file' is created in the 'magazine' table, which doesnt should happens. I've found some articles explaining how configure using annotation but yml I don't found nothing.

推荐答案

如果您阅读

If you read the documentation carefully, you'll notice that the upload-related configuration isn't mixed with doctrine's entity declaration.

您需要创建一个具有以下内容的src/Acme/DemoBundle/Resource/config/vich_uploader/Magazine.yml文件:

You need to create a src/Acme/DemoBundle/Resource/config/vich_uploader/Magazine.yml file with the following content:

Acme\DemoBundle\Entity\Magazine:
    file:
        mapping: magazine_cover
        filename_property: cover

您会在我的沙盒应用程序中找到工作代码示例.

这篇关于如何在yml映射的实体中配置VichUploader?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆