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?
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
