private function _createPad($name, $user) { $pad = new Pad(); $pad->setName($name); $pad->setUser($user); $this->getEm()->persist($pad); $this->getEm()->flush(); return $pad; }
/** * Creates a new pad. * * @Route("/pads/create", name="pad_create") * @Method({"GET", "POST"}) * * @param Request $request * * @return Response */ public function createAction(Request $request) { $pad = new Pad(); $pad->setUser($this->getUser()); $form = $this->createForm(new PadType(), $pad); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($pad); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'Pad is successfully created'); return $this->redirect($this->generateUrl('homepage')); } return $this->render('AppBundle:Pad:create.html.twig', ['form' => $form->createView()]); }