Symfony transaction commit, symfony commit
1. Add data
Create an object and assign values to the object
$ Em = $ this-> getDoctrine ()-> getManager (); // Add a transaction $ em-> getConnection ()-> beginTransaction (); try {$ model = new class (); $ model-> setName ($ name); $ em-> persist ($ model); $ em-> flush (); $ em-> getConnection ()-> commit ();} catch (\ Exception $ ex) {$ em-> getConnection ()-> rollback (); throw $ ex ;}
2. modify data
Bundle:table
Bundle name and table name
$ Obj = $ this-> getDoctrine ()-> getRepository ('bundle: table')-> findOneBy (array ('id' => $ id ));
$ Em = $ this-> getDoctrine ()-> getManager (); // Add a transaction $ em-> getConnection ()-> beginTransaction (); try {$ Obj-> setName ($ name); $ em-> persist ($ Obj); $ em-> flush (); $ em-> getConnection () -> commit ();} catch (\ Exception $ ex) {$ em-> getConnection ()-> rollback (); throw $ ex ;}
3. Delete
$Obj = $this->getDoctrine()->getRepository('Bundle:table')->findOneBy( array('id'=>$id));
$ Em = $ this-> getDoctrine ()-> getManager (); // Add a transaction $ em-> getConnection ()-> beginTransaction (); try {$ em-> remove ($ Obj); $ em-> flush (); $ em-> getConnection ()-> commit ();} catch (\ Exception $ ex) {$ em-> getConnection ()-> rollback (); throw $ ex ;}