1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public function editAction($id)
{
// pas nécessaire pour un update
// $uzer = new Uzer();
$repository = $this->getDoctrine()
->getManager()
->getRepository('SBUserBundle:Uzer');
// On récupère l'entité
$uzer= $repository->find($id);
if($uzer=== null)
{
throw $this->createNotFoundException('L\'utilisateur n\'existe pas');
}
// ne pas oublier de déclarer le namespace du UzerType
$form = $this->createForm(new UzerType(), $uzer);
$request = $this->get('request');
if ($request->getMethod() == 'POST') {
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($uzer);
$em->flush();
return $this->redirect($this->generateUrl('uzer_gest_view_user', array('id' => $uzer->getId(),'uzer'=>$uzer)));
}
}
return $this->render('SBUserBundle:UzerGest:edituzer.html.twig', array('id' => $myuzer->getId(),'form' => $form->createView($myuzer)));
} |