当前位置:网站首页>How do I delete an entity from symfony2
How do I delete an entity from symfony2
2022-06-25 19:57:00 【Superior virtue and weak water】
problem :
My first symfony2 project is a list of guests (invited in an event) stored in a database. My first one symfony2 Projects are stored in a database guest List of virtual machines ( Invited in the event ).I have I have a
- created the entity class Guest with all variables for them (id, name, address, phone number etc.) Created entity class Guest, Include all variables (id,name,address,phone number etc. )
- created the schema in the mysql db stay mysql db The schema is created in
- created a route for "adding a guest" to a twig template Created... For the branch template “ Add visitors ” The route of the
- created a formType Created a formType
and finally a "createGuest" method in the Controller and everything works fine. Last in Controller Use in “createGuest” Method , Everything is all right .
I can't manage to remove a guest from the database. I can't delete... From the database guest virtual machine .I have read every tutorial in the web, including the official Symfony2 book; I have read every tutorial on the Internet , Including the official Symfony2 book ;all that it says is : All it says is :
Deleting an Object Delete object
Deleting an object is very similar, but requires a call to the remove() method of the entity manager: Deleting objects is very similar , But you need to call the entity manager remove() Method :
$em->remove($product);$em->flush();
It does not say anything more than that (even the "Update an object" section is missing documentation) on how to connect the controller deleteAction($id) with the twig template. About how to put the controller deleteAction($ id) And twig The templates are connected , It doesn't say ( even to the extent that “ Update the object ” Some documents are missing ).What I want to do is to list all guests with a viewGuests action and a viewGuests twig template, having a delete icon next to every row, which you should click to delete an entry. What I want to do is to list all the items that have viewGuests Operation and viewGuests The guest of the branch template , There is a delete icon next to each line , You should click the icon to delete the entry .Simple, but I cannot find any documentation and do not know where to start from. It's simple , But I can't find any documents , I 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')); }
Solution :
Reference resources : https://stackoom.com/en/question/nYEn边栏推荐
- MySQL prompt performance_ Schema missing table
- PAT B1067
- New features of php7
- Jsonp processing non homologous
- Is CICC wealth safe? How long does it take to open an account
- Embark on a new journey and reach the world with wisdom
- How to understand var = a = b = C = 9? How to pre parse?
- Simple native JS tab bar switching
- ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
- Native JS array some method de duplication
猜你喜欢
ActiveMQ--CVE-2016-3088
Wechat applet swiper simple local picture display appears large blank
Using flex to implement the Holy Grail layout is as simple as that
ECS 7-day practical training camp (Advanced route) -- day03 -- ecs+slb load balancing practice
The native JS mobile phone sends SMS cases. After clicking the button, the mobile phone number verification code is sent. The button needs to be disabled and re enabled after 60 seconds
Jsonp processing non homologous
Mqtt+ardunio+esp8266 development (excluding mqtt server deployment)
Verification code native JS canvas
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
Can GoogleSEO only do content without external chain? (e6zzseo)
随机推荐
mysql load data infile
Mysql database design suggestions
Is it safe to open an online account for new bonds? What should be paid attention to
Network security detection and prevention test questions (I)
Processing method for uniapp or applet onload not receiving parameters
Embark on a new journey and reach the world with wisdom
Wechat applet swiper simple local picture display appears large blank
6、 Configuration resolution of hikariconfig
1、 Hikaricp source code analysis of connection acquisition process I
Panda weekly -2022/02/18
Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13
六、HikariConfig的配置解析
On Oracle full stack virtual machine -- graalvm
PAT B1071
Genicam gentl standard ver1.5 (1)
Web container basic configuration
Principles of MySQL clustered index and non clustered index
2.14(Knight Moves)
PAT B1067
Vscode debugging PHP configuration Xdebug