3

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

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 中进行了必要的配置:

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;

我没有这样工作,在“杂志”表中创建了一个字段“文件”,这不应该发生。我发现一些文章解释了如何使用注释进行配置,但是 yml 我什么也没找到。

4

1 回答 1

2

如果您仔细阅读文档,您会注意到与上传相关的配置并没有与学说的实体声明混合。

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

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

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

于 2014-07-09T17:58:53.680 回答