如何在 yml 映射的实体中配置 VichUploader?

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

问题描述

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

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

AcmeDemoBundleEntityMagazine:
  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 DoctrineORMMapping as ORM;

use SymfonyComponentHttpFoundationFileFile;
use SymfonyComponentValidatorConstraints as Assert;
use VichUploaderBundleMappingPropertyMapping as Vich;

我没有以这种方式工作,在杂志"表中创建了一个字段文件",这不应该发生.我发现一些文章解释了如何使用注释进行配置,但 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:

AcmeDemoBundleEntityMagazine:
    file:
        mapping: magazine_cover
        filename_property: cover

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)