I'm using Symfony2 Framework, and I want to update an entity with data from a form.
I'm using the same controller to populate the form with some data, and at the same time I'm using it to make the update query in the database. If I use $em->persist($foo) it does save exactly what I want, but I don't want to save it like it's new data, I want to update.
Reading symfony2 book, it says that $em->flush() is all we need so we can update.
I think I'm really close but of course I'm missing something.
Here's the code:
public function actualizarCurriculoAction($id){
$curriculo = new Curriculittle();
$form = $this->createForm(new CurriculittleType(), $curriculo);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
$lselect=$this->get('request')->request->get('lselect');
$edad=$this->get('request')->request->get('edad');
$estado=$this->get('request')->request->get('estadoselect');
if ($form->isValid()) {
$curriculo->setUsalentes($lselect);
$curriculo->setEdad($edad);
$curriculo->setEstado($estado);
$em = $this->getDoctrine()->getEntityManager();
/*em->persist($curriculo);*/
$em->flush(); /*the above line is in comment because I just want to update*/
/*At this point the entity should be updated, but it's not*/
/*Llamando a la plantilla de listados*/
$curriculos = $em->getRepository('SofLaSoflaBundle:Curriculittle')->findAll();
/*Enviando los datos a la plantilla y Renderizandola*/
return $this->render('SofLaSoflaBundle:Default:listado.html.twig', array('curriculos' => $curriculos));
}
}
$em = $this->getDoctrine()->getEntityManager();
$trabajador=$em->getRepository('SofLaSoflaBundle:Curriculittle')->find($id);
return $this->render('SofLaSoflaBundle:Default:curriculo.html.twig', array('form' => $form->createView(), 'curriculo' => $trabajador));
}
So, need help with this please. :)