/** * @Route("/deletenotice/{id}", name="deletenotice") * @ParamConverter("notice", class="AppBundle:Notice") * @Security("has_role('ROLE_ADMIN')") */ public function deleteNotice(Notice $notice) { $em = $this->getDoctrine()->getManager(); $users = $notice->getUsers(); foreach ($users as $user) { $notice->removeUser($user); $em->flush(); } $em->remove($notice); $em->flush(); return $this->redirectToRoute('noticelist'); }
/** * Creates a form to delete a Notice entity. * * @param Notice $notice The Notice entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Notice $notice) { return $this->createFormBuilder()->setAction($this->generateUrl('notice_delete', array('id' => $notice->getId())))->setMethod('DELETE')->getForm(); }