I have a MySQL database and frontend DataTables view and work with Symfony.
I have 2 buttons on my tables. Delete and edit. If I click on delete, it deletes the row from the DataTables and from MySqL. Works with this code:
/**
* @Route("/delete/{id}", name="deletepage")
* @Template()
*/
public function delete($id)
{
$em = $this->getDoctrine()->getManager();
$events = $em -> getRepository('AppBundle:eqAli')->find($id);
$em -> remove($events);
$em -> flush();
return $this->redirectToroute('homepage');
}
I have an edit button, which redirects to an edit page, where the data from that row is auto-filled. What I am trying to achieve is that once there is made a change by a user on that page and the user clicks on save, that the new information will be updated into MySQL. So no delete, but update.
I am trying to achieve that with this code:
/**
* @Route("/edit/update/{id}", name="updatepage")
* @Template()
*/
public function update($id)
{
$em = $this->getDoctrine()->getManager();
$events = $em -> getRepository('AppBundle:eqAli')->find($id);
$em -> persist($events);
$em -> flush();
return $this->redirectToroute('homepage');
}
But that does nothing. It does get the right ID, I can click, just no update into MySQL. The path etc is right because when I change persist into delete, the button works.
Anyone a solution?