Symfony 3中找不到模板

9
我知道有很多类似的问题,然而我没有找到解决方案。
我遇到了这个问题:
无法找到模板“CoreBundle:index.html.twig”(查看位置:/var/www/html/MyProject/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form)。
这是架构:enter image description here 这是我的控制器。
<?php

namespace CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="index")
     */
    public function indexAction(Request $request)
    {
        return $this->render('CoreBundle:index.html.twig');
    }

    /**
     * @Route("/ma-personnalite", name="ma-personnalite")
     */
    public function mapersonnaliteAction(Request $request)
    {
        return $this->render('CoreBundle:ma_personnalite.html.twig');
    }

    /**
     * @Route("/cv", name="cv")
     */
    public function cvAction(Request $request)
    {
        return $this->render('CoreBundle:cv.html.twig');
    }

    /**
     * @Route("/scolaires", name="scolaires")
     */
    public function scolairesAction(Request $request)
    {
        return $this->render('CoreBundle:scolaires.html.twig');
    }

    /**
     * @Route("/extra-scolaires", name="extra-scolaires")
     */
    public function extrascolairesAction(Request $request)
    {
        return $this->render('CoreBundle:extra_scolaires.html.twig');
    }

    /**
     * @Route("/contact", name="contact")
     */
    public function contactAction(Request $request)
    {
        return $this->render('CoreBundle:contact.html.twig');
    }
}

这是config.yml文件。
#app/config/routing.yml
core:
    resource: "@CoreBundle/Controller/"
    type:     annotation
    prefix:   /

感谢您的时间。
3个回答

19

根据Symfony 3文档,最好使用斜线而不是使用“Bundle”单词。

因此,我们以以下示例为例:

return $this->render('@BloggerBlog/Default/index.html.twig');

4

尝试更改此内容:

return $this->render('CoreBundle:index.html.twig');

转换为:

return $this->render('CoreBundle::index.html.twig');

区别在于使用 :: 而不是 :

非常感谢!当有一个文件夹时,我该怎么做才能包含它?(我想包含CoreBundle/Index/_meta.html.twig) - N.Jourdan
1
像这样:'CoreBundle :: example \ index.html.twig 我想,但你需要尝试 - Alessandro Minoccheri
你们是我的英雄。 - N.Jourdan
啊哈哈,很高兴能帮助你! - Alessandro Minoccheri

3
这在我的情况下帮了我: @Core/index.html.twig

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接