php - How to do edit function in symfony2 -
I wrote a function for editing in symfony2, my problem is that I can get previous values from the database But after submitting
public function editAction ($ id) {$ request = $ this- & gt; GetRequest} (); $ Em = $ this- & gt; GetDoctrine () - & gt; GetEntityManager (); $ Profile = $ em- & gt; GetRepository ('TcprofileBundle: TcProfiles') - & gt; Search ($ ID); $ Profile_form = $ this- & gt; CreateForm (new profile type), $ profile); $ Response = new JasonRespons (); $ Response- & gt; SetData (array ('content' = & gt; $ this- & gt; render view ('TcprofileBundle: default: create.html.twig', array ('form' => $ profile_form-> createView))) )); $ Refund; }
Html.twig file
& lt; Div class = "edit01" & gt; & Lt; A href = "#! {{Path ('tcprofile_edit', {'Id': profile.getId})}}" & gt; Edit profile & lt; / A & gt; & Lt; / Div & gt;
I am bringing out the old values, so if the loop is checked for this situation then
the controller
< Code> public function editAction ($ id) {$ request = $ this-> GetRequest (); $ Em = $ this- & gt; GetDoctrine () - & gt; GetEntityManager (); $ Profile = $ em- & gt; GetRepository ('TcprofileBundle: TcProfiles') - & gt; Search ($ ID); If (! $ Id) {$ profile_form = $ this- & gt; CreateForm (new profile type (), $ profile); $ Response = new JasonRespons (); $ Response- & gt; SetData (array ('content' = & gt; $ this- & gt; render view ('TcprofileBundle: default: create.html.twig', array ('form' => $ profile_form-> createView))) )); $ Refund; } And {$ profile- & gt; Upload (); $ Em- & gt; Continues ($ profile); $ Em- & gt; Flush (); $ Response = new JasonRespons (); $ Response- & gt; SetData (array ('content' = & gt; $ this- & gt; render view ('TcprofileBundle: default: create.html.twig', array ('form' => $ profile_form-> createView))) )); $ Refund; }}
It does not produce PLS helps me if I went wrong somewhere
When you update an entity, click $ em-> Instead of
. Please post $ em- & gt; merge ($ profile)
You can use continuous ($ profile)
Comments
Post a Comment