Bonjour,
J'utilise Gedmo pour télécharger mon fichier (https://github.com/Atlantic18/Doctri.../uploadable.md) tous se passe bien pour l'enregistrement en base et le téléchargement du fichier.
Mais voila dans que je recharge mon formulaire avec les données que jai en base, j'ai cette erreur ci-dessous.
Sachant que j'utilise l'entité donné dans l'exemple de uploadable et que jai testé en mettant data_class a nul ce qui me charge bien mon formulaire mais quand je l'envoie il me dit que le champ path n'est pas Symfony\Component\HttpFoundation\File\UploadedFile Object.The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Symfony\Component\HttpFoundation\File\File.
ci-dessous mon controller
Merci a vous.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 $files = $this->getDoctrine() ->getRepository('AcmeTestBundle:File') ->find(1); $form = $this->createFormBuilder($files) ->add('path','file') ->add('save', 'submit'); ->getForm() ; if ($this->getRequest()->getMethod() === 'POST') { $form->bind($this->getRequest()); if ($form->isValid()) { $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 = $this->getDoctrine()->getManager(); $em->persist($document); $em->flush(); } } return $this->render('AcmeTestBundle:form.html.twig', array( 'form' => $form->createView(), ));
Partager