How to configure VichUploader in entity mapped by yml?(如何在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 yml 映射的实体中配置 VichUploader?


- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01