Uploadable extension

Uploadable extensionΒΆ

Before using this extension, read the official Uploadable documentation. Once everything is ready, use the Form component as usual. Then, after you verify the form is valid, do the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$document = new Document();
$form = $this->createFormBuilder($document)
    ->add('name')
    ->add('myFile')
    ->getForm()
;

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
    $em = $this->getDoctrine()->getManager();
    $em->persist($document);

    $uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');

    // Here, "getMyFile" returns the "UploadedFile" instance that the form bound in your $myFile property
    $uploadableManager->markEntityToUpload($document, $document->getMyFile());

    $em->flush();

    return $this->redirect($this->generateUrl('...'));
}

return $this->render('...', array('form' => $form->createView()));

And that's it. The Uploadable extension handles the rest of the stuff. Remember to read its documentation!

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.