首页 文章

无法找到模板:创建一个简单的控制器和视图

提问于
浏览
0

我的控制器是/src/AppBundle/Controller/TestsController.php,类是:

class TestsController extends Controller
{
    /**
     * @Route("/tests/index", name="testsIndex")
     */
    public function indexAction(Request $request)
    {
        return $this->render('AppBundle::tests\index.html.twig', [
            'text' => "Hello world"
        ]);
    }
}

我的观点是/src/AppBundle/Resources/views/tests/index.html.twig并包含:

{{text}}

但是当我尝试打开http://localhost/project/web/tests/index时,错误显示:

无法找到模板“AppBundle :: tests / index.html.twig”(查看:D:\ www \ project \ app / Resources / views,D:\ www \ project \ vendor \ symfony \ symfony \ src \ Symfony \桥\嫩枝/资源/视图/表) .

我跟着这个线程,哪个错误几乎相同,但仍然找不到错误 . 这让我疯了 .

Unable to find template in Symfony 3

谢谢!

3 回答

  • 1

    应该工作,但尝试 AppBundle:tests:index.html.twig .

    您可能还想使用大写 Tests 而不是 tests . 更常规 .

  • 0

    Cerad的解决方案非常正确:

    @App/tests/index.html.twig
    
  • 0
    /**
     * @Route("/tests/index", name="testsIndex")
     */
    public function indexAction(Request $request)
    {
        return $this->render('tests\index.html.twig', [
            'text' => "Hello world"
        ]);
    }
    

    这应该工作 .

相关问题