Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created November 16, 2013 14:40
Show Gist options
  • Save glynrob/7500851 to your computer and use it in GitHub Desktop.
Save glynrob/7500851 to your computer and use it in GitHub Desktop.
/**
* @Route("/users/delete/{id}", requirements={"id" = "\d+"}, defaults={"id" = 0})
* @Template()
*/
public function deleteAction($id)
{
if ($id == 0){ // no user id entered
return $this->redirect($this->generateUrl('users_list_users_index'), 301);
}
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('UsersListBundle:Users')->find($id);
if (!$user) { // no user in the system
throw $this->createNotFoundException(
'No user found for id '.$id
);
} else {
$em->remove($user);
$em->flush();
return $this->redirect($this->generateUrl('users_list_users_index'), 301);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment