我有这个控制器动作:
/**
* @Route("/cms/comments/delete/{id}", name="_cms_comment_delete")
* @Template()
*/
public function deleteAction($id)
{
$comment = $this->getDoctrine()
->getRepository('CMSBundle:Comments')
->find($id);
if (!$comment) {
throw $this->createNotFoundException(
'error'
);
}
$em->remove($comment);
$em->flush();
$this->redirect($this->generateUrl('_cms_comments', array()));
}
此操作没有模板,我收到此错误:
Unable to find template "CMSBundle:Comments:delete.html.twig"
如何为此操作关闭渲染?
编辑:
当我删除@Template()注释时,我收到此错误:
The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
答案 0 :(得分:2)
删除
* @Template()
来自方法注释。
并添加return
声明:
return $this->redirect($this->generateUrl('_cms_comments', array()));