如何禁用Symfony 2.5.x twig模板加载器?

时间:2014-08-06 10:29:56

标签: symfony rendering twig

我有这个控制器动作:

/**
 * @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?

1 个答案:

答案 0 :(得分:2)

删除

 * @Template()

来自方法注释。

并添加return声明:

return $this->redirect($this->generateUrl('_cms_comments', array()));