コード例 #1
0
ファイル: GameController.php プロジェクト: OlliAB/doms-record
 /**
  * Creates a new Game entity.
  *
  * @Route("/new", name="game_new")
  * @Method({"GET", "POST"})
  * @Template("AppBundle:game:new.html.twig")
  */
 public function newAction(Request $request)
 {
     $game = new Game();
     $game->setUser($this->getUser());
     $form = $this->createForm(get_class(new GameType()), $game);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($game);
         $em->flush();
         return $this->redirectToRoute('game_show', array('id' => $game->getId()));
     }
     $repo = $this->container->get('doctrine')->getRepository('AppBundle:Nation');
     $nations = [$repo->findByAge(1), $repo->findByAge(2), $repo->findByAge(3)];
     return array('game' => $game, 'form' => $form->createView(), 'nations' => $nations);
 }