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?
				
        
 
            
        基础教程推荐
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php中的PDF导出 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				