【问题标题】:symfony 4 php template locationsymfony 4 php模板位置
【发布时间】:2018-02-06 06:51:38
【问题描述】:

请帮忙,symfony 4 找不到 php 模板。

错误是模板“::test/index.html.php”不存在。

控制器:

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class TestController extends Controller
{

    public function number()
    {
        $number = mt_rand(0, 100);

        // return new Response(
        //     '<html><body>Lucky number: '.$number.'</body></html>'
        // );
        return $this->render("test/number.html.php",
            array('number' => $number));
    }

    function index() {
        return $this->render("test/index.html.php");
    }
}

目录:

  • 模板/
    • 测试/
      • index.html.php
      • number.html.php

谢谢

【问题讨论】:

  • 你是否使用twig作为模板引擎?
  • 不,我正在使用 PHP 模板,已在配置中启用它
  • 可能重复,看这个帖子:link
  • symfony 4 中没有app/ 文件夹,模板有templates/ 文件夹
  • 也不行,试了链接改了:return $this-&gt;render("App:Test:index.html.php");

标签: php symfony templates symfony4


【解决方案1】:

带有 bundle:directory:filename 符号的快捷方式在 Symfony 4 中不再使用。而是使用相对于模板目录的真实路径,或者对于 bundle 使用带有 @ 前缀的语法。更多信息:http://symfony.com/doc/current/templating.html#template-naming-and-locations

如果你的错误来自第三方包,那么这个包还没有准备好与 Symfony 4 一起工作。然后你可以分叉包并更改控制器中的模板表示法。

【讨论】:

    【解决方案2】:

    您应该使用 Composer for PHP Engine 进行软件包安装。尝试清理缓存。检查“模板”目录的权限(755 或 777)。

    http://symfony.com/doc/master/templating/PHP.html

    【讨论】:

      【解决方案3】:

      php模板的存放位置是src\Resources\Views

      【讨论】:

        猜你喜欢
        • 2018-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-04
        • 2012-12-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多