【问题标题】:Unable to find template in Symfony 3在 Symfony 3 中找不到模板
【发布时间】:2017-06-10 18:23:24
【问题描述】:

我知道有很多这样的主题但是我没有找到解决方案

我有这个问题

找不到模板“CoreBundle:index.html.twig”(查看:/var/www/html/MyProject/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form)。

这是架构 这是我的控制器

<?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:   /

感谢您的宝贵时间

【问题讨论】:

    标签: php symfony templates bundle


    【解决方案1】:

    根据Symfony 3 Docs,最好使用斜杠,不要使用“捆绑”字样。

    所以,我们有一个例子:

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

    【讨论】:

      【解决方案2】:

      尝试改变这一点:

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

      到这里:

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

      不同的是使用::而不是:

      【讨论】:

      • 非常感谢!有文件夹时如何包含? (我想包含 CoreBundle/Index/_meta.html.twig)
      • 类似这样的东西:'CoreBundle::example\index.html.twig 我认为,但你需要尝试
      • 你是我的英雄
      • 哈哈很高兴为您提供帮助!
      【解决方案3】:

      这对我有帮助: @Core/index.html.twig

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-05
        • 2019-04-11
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多