Saturday, March 14, 2015

Symfony 2 - Duplicate an entity

public function duplicateAction(Request $request, $id){    $em = $this->getDoctrine()->getManager();    $entity = $em->getRepository('ABundle:B')->find($id);    if (!$entity) {        throw $this->createNotFoundException('Unable to find B entity.');    }    $new_entity = clone $entity;    $em = $this->getDoctrine()->getManager();    $em->persist($new_entity);    $em->flush();    return $this->indexAction();}

No comments:

Post a Comment

How to revert comments Youtube layout?

#see video for details  https://www.youtube.com/watch?v=J0L_nYtNlqs #uBlock Origin  https://chrome.google.com/webstore/detail/ublock-o...