public function contingentAction(Saison $saison) { $em = $this->getDoctrine()->getManager(); $session = $this->getRequest()->getSession(); $form = $this->createForm(new SaisonContingentType(), new SaisonContingent()); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { $data = $form->getData(); if ($saison->isInPeriode($data->getDebut()->format('Y-m-d'), $data->getFin()->format('Y-m-d'))) { $em->persist($data->setSaison($saison)); $em->flush(); $session->getFlashBag()->add('success', "Le contingent a été ajouté avec succées"); return $this->redirect($this->generateUrl('saison_contingent', array('id' => $saison->getId()))); } else { $form->get('debut')->addError(new FormError("Erreur dans les dates")); $form->get('fin')->addError(new FormError("Erreur dans les dates")); } } } return $this->render('BackHotelTunisieBundle:Saisons:contingent.html.twig', array('form' => $form->createView(), 'saison' => $saison, 'hotel' => $saison->getHotel())); }