3

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

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

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

Entity file:

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;

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.

cbacelar
  • 545
  • 7
  • 20

1 Answers1

2

If you read the documentation carefully, you'll notice that the upload-related configuration isn't mixed with doctrine's entity declaration.

You need to create a src/Acme/DemoBundle/Resource/config/vich_uploader/Magazine.yml file with the following content:

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

You will find working code samples in my sandbox application.

K-Phoen
  • 1,260
  • 9
  • 18
  • ok, it works now, thanks! but in edition mode the field 'file' cames empty. For your information: In the MagazineType, I said that 'file' is a 'file' widget, and 'cover' is 'hidden' (in edition mode, the file name cames in the value attr of 'cover' widget, how to pass to 'file'?). – cbacelar Jul 09 '14 at 20:52
  • @K-Phoen did you set the `protected $image` and `setImage()` in `src/KPhoen/Bundle/MultipleUploadableBundle/Entity/BikeImage.php` manually or is it generated somehow? – Asara Apr 18 '17 at 13:30