public function onUpload(\Oneup\UploaderBundle\Event\PostUploadEvent $event)
 {
     $object = new Image();
     $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery');
     $files = $manager->getFiles();
     $object->setFilename($files->getFilename());
     $this->manager->persist($object);
     $this->manager->flush();
 }
 /**
  * @Route("/{id}/edit-ad", name="edit-ad")
  * @ParamConverter("ad", class="AppBundle:Ad")
  *
  */
 public function editAction(Ad $ad, Request $request)
 {
     //        $this->enforceOwnerSecurity($ad);  SECURITY
     $form = $this->createForm(new AdFormType($this->getDoctrine()->getManager()), $ad);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery');
         $files = $manager->uploadFiles();
         foreach ($files as $file) {
             $image = new Image();
             $image->setFilename($file->getfileName());
             $em->persist($image);
             $image->setAd($ad);
         }
         $em->persist($form->getData());
         $em->flush();
         return $this->redirectToRoute("details", ['id' => $ad->getId()]);
     }
     return $this->render('ad/edit-ad.html.twig', array("form" => $form->createView(), "ad" => $ad));
 }