Esempio n. 1
0
 /**
  * @Route("/admin/soda/add")
  */
 public function createNewSoda(Request $request)
 {
     $entityManager = $this->getDoctrine()->getManager();
     $soda = new Soda();
     $form = $this->createForm(new SodaType(), $soda);
     $form->add('save', 'submit', array('label' => 'Create Soda'));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $entityManager->persist($soda);
         $entityManager->flush();
         $stock = new Stock();
         $stock->setId($soda->getId());
         $entityManager->persist($stock);
         $stock->addSoda($soda);
         $stock->setInStock(0);
         $entityManager->flush();
         return $this->redirectToRoute('admin_overview');
     }
     return $this->render('admin/Soda.html.twig', array('form' => $form->createView()));
 }