【问题标题】:symfony4 test.html.php template does not existsymfony4 test.html.php 模板不存在
【发布时间】:2018-07-16 11:11:18
【问题描述】:

通过编辑config/packages/framework.yaml启用php引擎后,我现在面临“模板:::/test/test.html.php”不退出”错误!!

控制器:

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class TestController extends Controller
    {
    /**
    * @Route("/test.html.php", name="testphp")
    */
    public function testphp(){
        return $this->render('test/test.html.php');
    }
}

路径:Templates/test/test.html.php

【问题讨论】:

  • 我们能看到你的文件树吗?
  • 你确定不是 test/test.html.twig
  • 附带说明:您的路线不必具有扩展名(或者甚至是相同的名称!)。你可以简单地拥有* @Route("/test", name="testphp")
  • 感谢您的评论!

标签: php symfony4


【解决方案1】:

我想通了。 Symfony 团队还没有更新 php 模板引擎,所以它查找的文件不在templates 文件夹中,而是在src/Resources/views/ 中。如果您将文件放在src\Resources\views\test\test.html.php 中,一切正常(我测试过)。

【讨论】:

  • 不客气。我也会考虑使用 Twig,因为在 Symfony 4 中似乎不再需要整个 php 模板。请参阅我创建的相关 github 问题:github.com/symfony/symfony/issues/27964
  • 感谢您的酷建议,但在进行了解决第一个问题的更改后,我调整了 require_once 的路径以适应所需文件的新资源/视图位置,现在我有另一个关键问题,` 自动加载器预期类“App\Resources\views\test\config”将在文件“/home/user1645/projects/application_symfony/vendor/composer/../../src/Resources/views/ 中定义”测试/test.config”。找到文件但类不在其中,类名或命名空间可能有错字。 `
  • 我不确定“我调整了 require_once 的路径”是什么意思。我认为最好只用你的代码创建一个新问题,这样我(和其他人)就可以看看可能是什么问题。
  • 我昨天以某种方式解决了这个问题,再次感谢您的帮助。
【解决方案2】:

运行 composer require symfony/twig-bundle 你会得到一个带有 base.html.twig 文件的模板文件夹

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 2014-03-10
    • 2017-01-23
    相关资源
    最近更新 更多