/** * @Route("/new", name="profile_new") * @Route("/edit/{id}", name="profile_edit", requirements={"id" = "\d+"}) * @Template() */ public function editAction(Request $request, $id = null) { $em = $this->get('doctrine')->getManager(); $profile = null; if (is_null($id)) { $profile = new Profile(); $profileExtended = new ProfileExtended(); $profile->setProfileExtended($profileExtended); } else { $profile = $em->getRepository('AppBundle:Profile')->findProfileByIdJoined($id); } $form = $this->createForm(new ProfileType(), $profile, array())->add('save', 'submit', array('label' => 'app.buttons.save')); $form->handleRequest($request); if ($form->isValid()) { $em->persist($profile); $em->flush(); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('app.flash.profile.saved')); return new RedirectResponse($this->generateUrl('profile_show', array('id' => $profile->getId()))); } elseif ($this->formHasErrors($form)) { $this->get('session')->getFlashBag()->add('danger', $this->get('translator')->trans('app.form.errors')); } return array('profile' => $profile, 'form' => $form->createView()); }