Reputation: 21
This is my controller - right from documentation
<?php
namespace Votes\VotesBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Votes\VotesBundle\Entity\File as File;
class FileController extends Controller
{
/**
* @Template()
*/
public function newAction()
{
$file = new File();
$form = $this->createFormBuilder($file)
->add('name')
->add('file','file')
->getForm()
;
if ($this->getRequest()->getMethod() === 'POST') {
$form->bind($this->getRequest());
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($file);
$uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
// Here, "getMyFile" returns the "UploadedFile" instance that the form bound in your $myFile property
$uploadableManager->markEntityToUpload($file, $file->getFile());
$em->flush();
$this->redirect($this->generateUrl('/file/new'));
}
}
return array('form' => $form->createView());
}
}
Here's my File entity
<?php
se Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* File
*
* @ORM\Table(name="files")
* @ORM\Entity
* @Gedmo\Uploadable( allowOverwrite=true, appendNumber=true, filenameGenerator="SHA1")
*/
class File
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="path", type="string")
* @Gedmo\UploadableFilePath
*/
private $path;
/**
* @ORM\Column(name="name", type="string")
* @Gedmo\UploadableFileName
*/
private $name;
/**
* @ORM\Column(name="mime_type", type="string")
* @Gedmo\UploadableFileMimeType
*/
private $mimeType;
/**
* @ORM\Column(name="size", type="decimal")
* @Gedmo\UploadableFileSize
*/
private $size;
private $file;
public function setFile($file)
{
$this->file = $file;
return $this;
}
public function getFile()
{
return $this->file;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set path
*
* @param string $path
* @return File
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Set name
*
* @param string $name
* @return File
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set mimeType
*
* @param string $mimeType
* @return File
*/
public function setMimeType($mimeType)
{
$this->mimeType = $mimeType;
return $this;
}
/**
* Get mimeType
*
* @return string
*/
public function getMimeType()
{
return $this->mimeType;
}
/**
* Set size
*
* @param string $size
* @return File
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* Get size
*
* @return string
*/
public function getSize()
{
return $this->size;
}
}
I get this error when submit form:
An exception occurred while executing 'INSERT INTO files (path, name, mime_type, size) VALUES (?, ?, ?, ?)' with params [null, "asdasdasd", null, null]:
If I'm correct - the uploadable extension - must fill my File entity with correct data in events? I'm right?
Upvotes: 2
Views: 492