/** {% block phpdoc_method_header %} * Edits an existing {{ entity }} entity. {% endblock phpdoc_method_header %} * {% block phpdoc_method_annotations %} {% if 'annotation' == format %} * @Route("/{id}", name="{{ route_name_prefix }}_update") * @Method("PUT") * @Template("{{ bundle }}:{{ entity }}:edit.html.twig") {% endif %} {% endblock phpdoc_method_annotations %} */ {% block method_definition %} public function updateAction(Request $request, $id) {% endblock method_definition %} { {% block method_body %} $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('{{ bundle }}:{{ entity }}')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find {{ entity }} entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); if ($editForm->isValid()) { $em->flush(); return $this->redirect($this->generateUrl('{{ route_name_prefix }}_edit', array('id' => $id))); } {% endblock method_body %} {% block method_return %} {% if 'annotation' == format %} return array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); {% else %} return $this->render('{{ bundle }}:{{ entity|replace({'\\': '/'}) }}:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); {% endif %} {% endblock method_return %} }