找不到模板Symfony 4

ercv8c1e  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(159)

当我从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).

验证码

framework.yaml

framework:
    templating:
        engines: ['twig']

twig.yaml

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

SecurityController.php

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

版本号

Symfony 4.0
PHP 7.3
小枝/小枝2.14
wig/templating 4.0
sensio/framework-extra-bundle 5.2.4

pnwntuvh

pnwntuvh1#

将路径设置为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. wig

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

相关问题