<?php
// ...
public function buildForm(FormBuilder $builder, array $options)
{
$builder
// ...
->add('handle', 'genemu_jqueryfile');
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Genemu\Bundle\EntityBundle\Entity\File'
);
}
<?php
namespace MyNamespace;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class MyClassController extends Controller
{
public function fileAction()
{
$em = $this->getDoctrine()->getEntityManager();
$file = $em->getRepository('GenemuEntityBundle:File')->find(1);
$form = $this->createForm(new FileType(), $file);
$options = $this->container->getParameter('genemu.form.jqueryfile.options');
$folder = $options['folder'];
if ($this->getRequest()->getMethod() === 'POST') {
$form->bindRequest($this->getRequest());
if ($form->isValid()) {
if ($handle = $file->getHandle()) {
$file->setName($handle->getBasename('.' . $handle->guessExtension()));
$file->setSize($handle->getSize());
$file->setMimeType($handle->getMimeType());
$file->setContent(file_get_contents($handle->getPathname()));
}
$em->persist($file);
$em->flush();
}
}
}
}