public function newAction(Request $request) { $em = $this->getDoctrine()->getManager(); $task = new Task(); $task->setName('Task name'); // dummy code - this is here just so that the Task has some tags // otherwise, this isn't an interesting example $product1 = new Product(); $product1->setName('prodct1'); $product1->setPrice('11.11'); $task->getProducts()->add($product1); $product2 = new Product(); $product2->setName('product2'); $product2->setPrice('22.22'); $task->getProducts()->add($product2); $form = $this->createForm(TaskType::class, $task); $form->handleRequest($request); if ($form->isValid()) { $em->persist($task); $em->flush(); return $form->get('saveAndAdd')->isClicked() ? $this->redirectToRoute('task_new', [], 301) : $this->redirectToRoute('task_list', [], 301); } return $this->render('AppBundle:Task:new.html.twig', array('form' => $form->createView())); }