I have a problem with editing an entity that has a file. I followed the Symfony documentation for uploading a file and it works fine. At creation my file is stored well in my upload folder and the encrypted name stored in database.
For the edition I followed the documentation so as not to have any error, I quote:
When creating a form to edit an already persisted item, the file form type still expects a File instance. As the persisted entity now contains only the relative file path, you first have to concatenate the configured upload path with the stored filename and create a new File class
And it worked.
But on the form's display, the file field says "No file selected"
Here is my controller :
public function editAction(Request $request, Produits $entity)
    {
        $entity->setPhoto(
            new File($this->getParameter('images_directory').'/'.$entity->getPhoto())
        );
        $form = $this->createForm('ProjectBundle\Form\Produit\ProduitType', $entity);
        $form->handleRequest($request);
        if ($form->isSubmitted()) {
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($entity);
                $em->flush();
                $this->addFlash('success', 'Le produit "'.$entity.'" a été modifié.');
                return $this->redirectToRoute('produit_show', array('id' => $entity->getId()));
            }
        } elseif ($form->isSubmitted()) {
            $this->addFlash('error', 'Le produit "'.$entity.'" n\'a pas pu être modifié.');
        }
        return $this->render('ProjectBundle:admin/Produit:edit.html.twig', array(
            'entity' => $entity,
            'form' => $form->createView(),
        ));
    }
And in my view :
<div class="input-field{% if form.photo.vars.errors|length %} has-error{% endif %}">
    {{ form_widget(form.photo,{'attr': {'class': 'form-control'}}) }}
    {{ form_errors(form.photo) }}
</div>
If I do a {{ dump(form.photo) }} I get all information about the photo belonging to my entity.
Do you have an idea to get the name of the image in the field ?
Thanks !
 
     
     
    