He seguido el siguiente tutorial https://symfonytricksandcheats.wordpress.com/2015/11/05/subir-multiples-ficheros-a-la-vez/
Y tras seguirlo me devuelve el siguiente error:
Error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Debug\ErrorHandler::handleException() must be an instance of Exception, instance of Error given in /Applications/MAMP/htdocs/miweb/vendor/symfony/symfony/src/Symfony/Component/Debug/ErrorHandler.php:436 Stack trace: #0 [internal function]: Symfony\Component\Debug\ErrorHandler->handleException(Object(Error)) #1 {main} thrown
No termino de entenderlo, lo que sé he visto es que el error está en el controlador, el cual es:
public function createAction(Request $request) { $album = new Album(); $form = $this->createForm(new AlbumType(), $album); $form->handleRequest($request); if ($form->isValid()) { // Handle the uploaded images $files = $form->getData()->getPicture(); // If there are images uploaded if($files != null) { $constraints = array('maxSize'=>'10M', 'mimeTypes' => array('image/*')); $uploadFiles = $this->get('app.fileuploader')->create($files, $constraints); if($uploadFiles->upload()) { $album->setPicture($uploadFiles->getFilePaths()); $em = $this->getDoctrine()->getEntityManager(); $em->persist($album); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'Las imagenes se han subido con éxito.'); } // If there are file constraint validation issues else { // Check for errors foreach($uploadFiles->getErrors() as $error) { $this->get('session')->getFlashBag()->add('error', $error); } return $this->render('FrontEndBundle:AlbumOld:uploadAlbum.html.twig', array( 'entity' => $album, 'form' => $form->createView(), )); } } } return $this->render('FrontEndBundle:AlbumOld:uploadAlbum.html.twig', array( 'form' => $form->createView() ));
Twig
{{ form_label(form.name) }} {{ form_widget(form.name) }}
{{ form_label(form.picture) }} {{ form_widget(form.picture, { 'full_name': 'simplex_album[picture]' ~ '[]' } ) }}
{% if error is defined %} {% for errorMessage in error %}
Album.php
add('name') ->add('ìcture', 'file', array( 'attr' => array( 'accept' => 'image/*', 'multiple' => 'multiple' ), 'data_class' => null ) ); } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'simplex\Entity\Album' )); } /** * @return string */ public function getName() { return 'simplex_album'; } }
Si elimino el código que está en negrita no me da este error, me da otro diferente, pero es el único código que si lo quito cambia el error que me muestra.