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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('AdresGestionBundle:Annonce')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Annonce entity.');
}
$photoArray = $em->getRepository('AdresGestionBundle:Photo')->findBy(array('annonce' => $entity));
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$entity->setDateModificationAnnonce(new \DateTime());
$entity->setUserModif($this->getUser());
foreach($photoArray as $key=>$ph){
$em->persist($ph);
}
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('annonce', array('id' => $id)));
}
return $this->render('AdresGestionBundle:Annonce:index.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} |
Partager