示例#1
0
 /**
  * Edits an existing Contact entity.
  *
  * @param Request $request Request
  * @param Contact $contact Contact
  *
  * @throws NotFoundHttpException
  *
  * @return RedirectResponse|Response
  *
  * @Route("/contact/update/{id}", name="contact_update")
  * @Method({"GET", "PUT"})
  * @ParamConverter("contact", class="AppBundle:Contact")
  * @Template("AppBundle:Contact:edit.html.twig")
  */
 public function updateAction(Request $request, Contact $contact)
 {
     if ($this->getUser() !== $contact->getUser()) {
         throw $this->createNotFoundException('Unable to find Contact entity.');
     }
     $em = $this->getDoctrine()->getManager();
     $deleteForm = $this->createDeleteForm($contact->getId());
     $editForm = $this->createEditForm($contact);
     $editForm->handleRequest($request);
     if ($editForm->isValid()) {
         $em->flush();
         return $this->redirect($this->generateUrl('contact_show', ['id' => $contact->getId()]));
     }
     return ['entity' => $contact->getId(), 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()];
 }
 /**
  * Creates a form to delete a Contact entity.
  *
  * @param Contact $contact The Contact entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Contact $contact)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('contact_delete', array('id' => $contact->getId())))->setMethod('DELETE')->getForm();
 }
 /**
  * Creates a form to delete a Contact entity.
  *
  * @param Contact $contact The Contact entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Contact $contact = null)
 {
     if ($contact === null) {
         return $this->render('contact/not_found.html.twig');
     }
     return $this->createFormBuilder()->setAction($this->generateUrl('crud_contact_delete', array('id' => $contact->getId())))->setMethod('DELETE')->getForm();
 }