/** * @Route("/example/create", name="examplecreate") */ public function createAction() { $amount = new Amount(); $amount->setName('liter'); $amount2 = new Amount(); $amount2->setName('kg'); $category = new Category(); $category->setName('spices'); $category2 = new Category(); $category2->setName('liquids'); $ingredient = new Ingredient(); $ingredient->setName('milk'); $ingredient->setAmount(2); $ingredient->setCategoryID($category); $ingredient->setAmountID($amount2); $em = $this->getDoctrine()->getManager(); $em->persist($amount); $em->persist($amount2); $em->persist($category); $em->persist($category2); $em->persist($ingredient); $em->flush(); return $this->render('default/index.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'))); }