My first symfony2 project is a list of guests (invited to an event) stored in a database. I have
- created an entity of the Guest class with all the variables for them (identifier, name, address, phone number, etc.).
- created a schema in mysql db
- created a route to add a "guest" to the branch template.
- created formType
and finally, the createGuest method in the controller, and everything works fine.
I will not be able to remove the guest from the database. I read every tutorial on the Internet, including the official Symfony2 book; all he says:
Delete object
Removing an object is very similar, but requires calling the remove () method of the entity manager:
$em->remove($product); $em->flush();
It does not say anything (even in the "Refresh Object" section there is no documentation) on how to connect the deleteAction ($ id) controller with the branch template. What I want to do is list all the guests using the viewGuests action and the twig viewGuests template, which has a delete icon next to each line that you have to click to delete the entry. Simple, but I canโt find the documentation and donโt know where to start.
public function deleteGuestAction($id) { $em = $this->getDoctrine()->getEntityManager(); $guest = $em->getRepository('GuestBundle:Guest')->find($id); if (!$guest) { throw $this->createNotFoundException('No guest found for id '.$id); } $em->remove($guest); $em->flush(); return $this->redirect($this->generateUrl('GuestBundle:Page:viewGuests.html.twig')); }
symfony doctrine
Radolino Aug 04 2018-12-12T00: 00Z
source share