1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public function delAction($id)
{
$em = $this->getDoctrine()->getManager();
$post = $em->getRepository('AdminBundle:Post')->find($id);
if(!$post)
throw $this->createNotFoundException('Aucun post trouvé pour cet id : '.$id);
$values = $em->getRepository('AdminBundle:FieldPostValue')->findBy(array('post' => $id));
foreach($values as $value)
{
$post->removeFieldsPostsValue($value);
$em->remove($value);
}
$em->remove($post);
$em->flush();
return $this->redirect($this->generateUrl('posts'));
} |