symfony - Doctrine uploadable: Multiple file upload on the same entity -


i'm using excellent doctrine extension uploadable. can upload 1 file per entity fine, how can upload 2 different files on same entity?

* @gedmo\uploadable(path="uploads/articles", appendnumber=true, filenamegenerator="sha1") class article {     * @orm\column(name="photo", type="string", length=255)     * @gedmo\uploadablefilepath     private $photo      * @orm\column(name="pdf", type="string", length=255)     * @gedmo\uploadablefilepath     private $pdf 

on controller have:

$uploadablemanager->markentitytoupload($article, $article->getphoto()); $uploadablemanager->markentitytoupload($article, $article->getpdf()); 

only last file uploaded , saved database. how can this?

you confused something.

you have article entity 2 fields: photo , pdf, there no $materia entity. should change $materia $article. won't work because @uploadable cannot upload multiple files same entity.

hint: use vichuploaderbundle doctrine file uploads handling

upd: here example class.

<?php  namespace acme\demobundle\entity;  use doctrine\orm\mapping orm; use symfony\component\httpfoundation\file\file; use vich\uploaderbundle\mapping\annotation vich;  /**  * @orm\entity  * @orm\table(name="article")  * @vich\uploadable  */ class article {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     private $id;      // ..... other fields      /**      * note: not mapped field of entity metadata, simple property.      *      * @vich\uploadablefield(mapping="article_photo", filenameproperty="photoname")      *      * @var file      */     private $photofile;      /**      * @orm\column(type="string", length=255)      *      * @var string      */     private $photoname;       /**      * note: not mapped field of entity metadata, simple property.      *      * @vich\uploadablefield(mapping="article_pdf", filenameproperty="pdfname")      *      * @var file      */     private $pdffile;      /**      * @orm\column(type="string", length=255)      *      * @var string      */     private $pdfname;      /**      * @orm\column(type="datetime")      *      * @var \datetime      */     private $updatedat;      /**      * @return mixed      */     public function getid()     {         return $this->id;     }      /**      * @return \datetime      */     public function getupdatedat()     {         return $this->updatedat;     }      /**      * @param \datetime $updatedat      * @return article      */     public function setupdatedat(\datetime $updatedat)     {         $this->updatedat = $updatedat;          return $this;     }      /**      * if manually uploading file (i.e. not using symfony form) ensure instance      * of 'uploadedfile' injected setter trigger  update. if      * bundle's configuration parameter 'inject_on_load' set 'true' setter      * must able accept instance of 'file' bundle inject 1 here      * during doctrine hydration.      *      * @param file|\symfony\component\httpfoundation\file\uploadedfile $photo      *      * @return article      */     public function setphotofile(file $photo = null)     {         $this->photofile = $photo;          if ($photo) {             // required @ least 1 field changes if using doctrine             // otherwise event listeners won't called , file lost             $this->updatedat = new \datetime('now');         }          return $this;     }      /**      * @return file      */     public function getphotofile()     {         return $this->photofile;     }      /**      * @param string $photoname      *      * @return article      */     public function setphotoname($photoname)     {         $this->photoname = $photoname;          return $this;     }      /**      * @return string      */     public function getphotoname()     {         return $this->photoname;     }       /**      * if manually uploading file (i.e. not using symfony form) ensure instance      * of 'uploadedfile' injected setter trigger  update. if      * bundle's configuration parameter 'inject_on_load' set 'true' setter      * must able accept instance of 'file' bundle inject 1 here      * during doctrine hydration.      *      * @param file|\symfony\component\httpfoundation\file\uploadedfile $pdf      *      * @return article      */     public function setpdffile(file $pdf = null)     {         $this->pdffile = $pdf;          if ($pdf) {             // required @ least 1 field changes if using doctrine             // otherwise event listeners won't called , file lost             $this->updatedat = new \datetime('now');         }          return $this;     }      /**      * @return file      */     public function getpdffile()     {         return $this->pdffile;     }      /**      * @param string $pdfname      *      * @return article      */     public function setpdfname($pdfname)     {         $this->pdfname = $pdfname;          return $this;     }      /**      * @return string      */     public function getpdfname()     {         return $this->pdfname;     } } 

and need configure vichuploader way:

# app/config/config.yml vich_uploader:     db_driver: orm      mappings:         article_photo:             uri_prefix:         /images/articles/photos             upload_destination: %kernel.root_dir%/../web/images/articles/photos         article_pdf:             uri_prefix:         /images/articles/pdfs             upload_destination: %kernel.root_dir%/../web/images/articles/pdfs 

be attentive. can confused configuration, mappings, methods... read manual , thoughtly. https://github.com/dustin10/vichuploaderbundle/blob/master/resources/doc/usage.md


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -