-
-
Save ftassi/bbd95b5356f7d9058d7c to your computer and use it in GitHub Desktop.
VichUploaderBundle issue #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vich_uploader: | |
web_dir_name: web | |
db_driver: orm # or mongodb | |
mappings: | |
user_photo: | |
upload_dir: %kernel.root_dir%/../web/uploads/photo | |
delete_on_remove: false | |
inject_on_load: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* @Route("/", name="_demo") | |
* @Template() | |
*/ | |
public function indexAction() | |
{ | |
$document = new \Acme\DemoBundle\Entity\Document(); | |
$form = $this->createFormBuilder($document) | |
->add('photo', 'file') | |
->getForm(); | |
if ($this->getRequest()->getMethod() == 'POST') | |
{ | |
$form->bindRequest($this->getRequest()); | |
if ($form->isValid()) | |
{ | |
$em = $this->getDoctrine()->getEntityManager(); | |
$em->persist($document); | |
$em->flush(); | |
} | |
} | |
return array('form' => $form->createView()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Vich\UploaderBundle\Mapping\Annotation as Vich; | |
/** | |
* Acme\DemoBundle\Entity\Document | |
* | |
* @ORM\Table() | |
* @ORM\Entity | |
* @Vich\Uploadable | |
*/ | |
class Document | |
{ | |
/** | |
* @var integer $id | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @Vich\UploadableField(mapping="user_photo", fileNameProperty="photoName") | |
* @var type | |
*/ | |
protected $photo; | |
/** | |
* @ORM\Column(type="string", length=255, name="photo_name", nullable=true) | |
* | |
* @var string $photoName | |
*/ | |
protected $photoName; | |
/** | |
* @ORM\Column(type="string", length=255, name="title", nullable=true) | |
* | |
* @var string $title | |
*/ | |
protected $title; | |
public function getPhoto() | |
{ | |
return $this->photo; | |
} | |
public function setPhoto($photo) | |
{ | |
$this->photo = $photo; | |
} | |
public function getPhotoName() | |
{ | |
return $this->photoName; | |
} | |
public function setPhotoName($photoName) | |
{ | |
$this->photoName = $photoName; | |
} | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment