public function occChambreAction(Saison $saison) { $em = $this->getDoctrine()->getManager(); $session = $this->getRequest()->getSession(); $request = $this->getRequest(); foreach ($saison->getHotel()->getChambres() as $ch) { $verif = $em->getRepository("BackHotelTunisieBundle:SaisonChambre")->findBy(array('saison' => $saison, 'chambre' => $ch)); if (count($verif) == 0) { $saisonChambres = new SaisonChambre(); $saisonChambres->setChambre($ch); $saison->addChambre($saisonChambres); } } $form = $this->createForm(new SaisonCType(), $saison); if ($request->isMethod("POST")) { $form->bind($request); if ($form->isValid()) { $saison = $form->getData(); foreach ($saison->getChambres() as $chambres) { $em->persist($chambres->setSaison($saison)); } $em->flush(); $session->getFlashBag()->add('success', " Votre saison a été modifié avec succées "); return $this->redirect($this->generateUrl("OccChambreSaison", array('id' => $saison->getId()))); } } return $this->render('BackHotelTunisieBundle:Saisons:occ_chambres.html.twig', array('hotel' => $saison->getHotel(), 'saison' => $saison, 'form' => $form->createView())); }