无法找到模板 Symfony 4

问题描述 投票:0回答:2

当我从Symfony 3.4更新到Symfony 4并用浏览器显示系统时,出现以下错误。
更改视图目录是一项繁重的工作,我不想尽可能多地这样做。有什么好的办法吗?
错误代码

Unable to find template "AhiSpAdminBundle:Security:login.html.twig" (looked into: /home/vagrant/Symfony/src/Sp/AppBundle/Resources/views, /home/vagrant/Symfony/templates, /home/vagrant/Symfony/vendor/symfony/twig-bridge/Resources/views/Form).

代码
框架.yaml

framework:
    templating:
        engines: ['twig']

twig.yaml

twig:
    paths: ['%kernel.project_dir%/src/App/AppBundle/Resources/views']
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'

安全控制器.php

    /**
     * @Route("/login")
     * @Template("SpAppBundle:Security:login.html.twig")
     */
    public function loginAction(Request $request)
    {

版本
交响乐 4.0
PHP 7.3
树枝/树枝 2.14
树枝/模板 4.0
sensio/框架额外捆绑包 5.2.4

symfony twig
2个回答
0
投票

设置 twig.yaml 的路径以及伴随的更改有效。

twig.yaml

twig:
    paths:
        '%kernel.project_dir%/src/Sp/AppBundle/Resources/views': SpApp

控制器

    /**
     * @Route("/login")
     * @Template("@SpApp/Security/login.html.twig")
     */
    public function loginAction(Request $request)
    {

~.html.twig

{% extends '@SpApp/layout.html.twig' %}

-2
投票

从您的路径和代码中检查大写字母。在 Windows 中你没有问题,但是当你传递到 Linux 服务器时,你就会遇到问题。

© www.soinside.com 2019 - 2024. All rights reserved.