Created
July 10, 2016 11:52
-
-
Save pboethig/5c5d03f0dd83b4ff3e1b2c3893e84f22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Displays a form to edit an existing Users entity. | |
* | |
* @Route("/{id}/edit", name="users_edit") | |
* @Method({"GET", "POST"}) | |
*/ | |
public function editAction(Request $request, Users $user) | |
{ | |
$deleteForm = $this->createDeleteForm($user); | |
$editForm = $this->createForm('BlogBundle\Form\UsersType', $user); | |
$editForm->handleRequest($request); | |
if ($editForm->isSubmitted() && $editForm->isValid()) { | |
// 3) Encode the password (you could also do this via Doctrine listener) | |
$password = $this->get('security.password_encoder')->encodePassword($user, $user->getPassword()); | |
$user->setPassword($password); | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($user); | |
$em->flush(); | |
$this->get('session')->getFlashBag()->add('success', 'Edited Successfully!'); | |
return $this->redirectToRoute('users_edit', array('id' => $user->getId())); | |
} | |
return $this->render('users/edit.html.twig', array( | |
'user' => $user, | |
'edit_form' => $editForm->createView(), | |
'delete_form' => $deleteForm->createView(), | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment