/** * @Route("/reservation/{tourDateId}", name="reservation") */ public function reservationAction($tourDateId, Request $request) { $r = new Reservation(); $r->setTourDate($this->getDoctrine()->getRepository('AppBundle:TourDate')->find($tourDateId)); $form = $this->createFormBuilder($r)->add('name')->add('email', 'email')->add('country', 'country')->add('submit', 'submit')->getForm(); $form->handleRequest($request); if ($form->isValid()) { $r->setStatus('pending'); $this->getDoctrine()->getEntityManager()->persist($r); $this->getDoctrine()->getEntityManager()->flush(); $message = \Swift_Message::newInstance()->setSubject('New reservation')->setFrom('*****@*****.**')->setTo('*****@*****.**')->setBody($this->renderView('email/notification.html.twig', array('r' => $r)), 'text/html'); $this->get('mailer')->send($message); return $this->render('default/reservation_success.html.twig', array('r' => $r)); } return $this->render('default/reservation.html.twig', array('form' => $form->createView())); }