private function _createPad($name, $user)
 {
     $pad = new Pad();
     $pad->setName($name);
     $pad->setUser($user);
     $this->getEm()->persist($pad);
     $this->getEm()->flush();
     return $pad;
 }
Example #2
0
 /**
  * Delete a pad.
  *
  * @Route("/pads/{id}/delete", name="pad_delete")
  * @Method({"GET", "POST"})
  *
  * @param Pad     $pad
  * @param Request $request
  *
  * @return Response
  */
 public function deleteAction(Pad $pad, Request $request)
 {
     if ($pad->getUser()->getId() !== $this->getUser()->getId()) {
         throw $this->createNotFoundException('Pad not found');
     }
     if ($request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $em->remove($pad);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'Pad is successfully deleted');
         return $this->redirect($this->generateUrl('homepage'));
     }
     return $this->render('AppBundle:Pad:delete.html.twig', ['pad' => $pad]);
 }