Skip to content

Instantly share code, notes, and snippets.

@ftassi
Created May 8, 2012 22:31
Show Gist options
  • Save ftassi/bbd95b5356f7d9058d7c to your computer and use it in GitHub Desktop.
Save ftassi/bbd95b5356f7d9058d7c to your computer and use it in GitHub Desktop.
VichUploaderBundle issue #19
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
**
* @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());
}
<?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