在Symfony 2中无法使用render方法找到Twig模板 [英] Unable to find Twig template using render method in Symfony 2

查看:147
本文介绍了在Symfony 2中无法使用render方法找到Twig模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个试图引用特定Twig模板的问题。我正在使用作为SF2主控制器一部分的 render 方法,但我显然没有正确地引用/使用它。

I am experiencing an issue trying to reference a particular Twig template. I am using the render method that is part of the SF2 main controller, but I clearly not referencing/using it correctly.

这是我的目录/文件结构:

This is my directory/file structure:

/src
   /AyrshireMinis
      /CommonBundle
         /Controller
            DefaultController.php
         /Entity
            Link.php
         /Resources
            /views
               /Default
                  links.html.twig

这是路由器在 DefaultContoller.php中调用的方法

/**
 * @Route("/links", name="ayrshireminis_links")
 * @Template()
 */
public function linksAction()
{
    $links = $this->getDoctrine()->getRepository('AyrshireMinisCommonBundle:Link')->findAll();
    return $this->render('AyrshireMinisCommonBundle:Link:links.html.twig', array('links' => $links));
}

但这是我得到的错误:


无法找到模板
AyrshireMinisCommonBundle:Link:links.html.twig。

Unable to find template "AyrshireMinisCommonBundle:Link:links.html.twig".


推荐答案

我认为这是因为模板AyrshireMinisCommonBundle:Link:links.html.twig不存在,请尝试将其更改为AyrshireMinisCommonBundle: /strong>:links.html.twig

I think it's because the template "AyrshireMinisCommonBundle:Link:links.html.twig" does not exist, try changing it to "AyrshireMinisCommonBundle:Default:links.html.twig"

这篇关于在Symfony 2中无法使用render方法找到Twig模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆