コード例 #1
0
 public function delete(MyArray $data)
 {
     foreach ($data->getElements() as $element) {
         $this->_em->remove($element);
     }
     $this->_em->remove($data);
     $this->_em->flush();
 }
コード例 #2
0
 /**
  * Advanced usage
  *
  * Looks like there are weird behaviours with Doctrine:
  * https://github.com/ninsuo/symfony-collection/issues/7
  * Let's test that live!
  *
  * @Route(
  *      "/usageWithDoctrine/{name}",
  *      name = "usageWithDoctrine",
  *      defaults = {
  *          "name" = "example",
  *      }
  * )
  * @Template()
  */
 public function usageWithDoctrineAction(Request $request, $name)
 {
     // intializing the context
     $repo = $this->getDoctrine()->getRepository('FuzAppBundle:MyArray');
     $em = $this->getDoctrine()->getEntityManager();
     $data = $repo->findOneByName($name);
     if (is_null($data)) {
         $data = new MyArray();
         $data->setName($name);
         $em->persist($data);
         $em->flush();
     }
     // creating and processing the form
     $form = $this->createForm(new MyArrayType(), $data);
     $form->handleRequest($request);
     foreach ($data->getElements() as $element) {
         $element->setArray($data);
     }
     if ($form->isValid()) {
         $em->persist($data);
         $em->flush();
     }
     // rendering the view
     return array('form' => $form->createView(), "data" => $data);
 }