扩展FOSUserBundle的默认模板layout.html.twig时,Symfony Server崩溃 [英] Symfony Server crashes when extending FOSUserBundle's default template layout.html.twig

查看:39
本文介绍了扩展FOSUserBundle的默认模板layout.html.twig时,Symfony Server崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从FOSUserBundle运行基本的用户登录. 我正在使用Symfony 3.0.6.

I am trying to get the basic user login running from the FOSUserBundle. I am using Symfony 3.0.6.

我按照说明从FOSUserBundle设置了所有内容: https://symfony.com/doc/master/bundles/FOSUserBundle/index.html

I followed the description to setup everything from the FOSUserBundle: https://symfony.com/doc/master/bundles/FOSUserBundle/index.html

数据库已启动并且正在运行,一切正常,除非我无法弄清楚如何从FOSUserBundle中覆盖layout.html.twig. 我遵循以下描述实现了这一目标: https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html

DB is up and running everything seems fine except I cant figure out how to override the layout.html.twig from the FOSUserBundle. I followed this description for achieving that: https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html

我现在在"Resources/FOSUserBundle/views"文件夹中有一个文件"layout.html.twig",其内容与上面提供的最后一个链接相同. 这会导致以下错误:

I now have a file "layout.html.twig" in the folder "Resources/FOSUserBundle/views" with the content being the same as in the last link provided above. This leads to the following error:

无法找到模板"layout.html.twig"(调查: 第1行的FOSUserBundle :: layout.html.twig中的[somePathInfo]).

Unable to find template "layout.html.twig" (looked into: [somePathInfo]) in FOSUserBundle::layout.html.twig at line 1.

现在,我将"layout.html.twig"模板中的第一行更改为

Now I changed the first line in the "layout.html.twig" Template to be

{% extends 'FOSUserBundle::layout.html.twig' %}

然后这导致symfony服务器崩溃说明

And this then leads to the symfony server to crash stating

>php bin/console server:run -v                                                                                                                       
 [OK] Server running on http://127.0.0.1:8000                                                                           
 // Quit the server with CONTROL-C.
  RUN  "C:\xampp\php\php.exe" "-S" "127.0.0.1:8000" "[PATH]\myProject\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\router_dev.php"
  RES  -1073741571 Command did not run successfully
 [ERROR] Built-in server terminated unexpectedly.

我被困在这里... 任何想法都非常欢迎.

I am stuck here... Any ideas are very welcome.

由作曲家安装的FOSUserBundle(我通过当前的PHP-Storm插件使用)安装在以下路径:

The FOSUserBundle installed by the composer (which I use through the current PHP-Storm plugin) is installed at the path:

[projectPath]\vendor\friendsofsymfony\user-bundle\Resources\views\layout.html.twig

但是在文档中总是提到"FOSUserBundle",我不知道如何确定该映射是否适合我项目中的路径. 任何有关此问题的提示也非常欢迎.

In the docu however allways "FOSUserBundle" only is mentioned and I don't know how to figure out if that mapping fits to the path in my project. Any hints for this issue are very wellcome as well.

推荐答案

覆盖标准FOSUser布局时,需要将布局放入app/Resources/FOSUserBundle/views/layout.html.twig.太好了,您做到了.它只是一个布局,不应扩展标准的FOSUser布局,因此请删除行{% extends 'FOSUserBundle::layout.html.twig' %}.但是通常开发人员会制作一个基本布局,在我的情况下是\app\Resources\views\base.html.twig,因此,如果要覆盖fosuser布局,我会在app/Resources/FOSUserBundle/views/layout.html.twig中使用类似的内容

When you override standart FOSUser layout you need to place your layout into app/Resources/FOSUserBundle/views/layout.html.twig. great, you did this. it's just a layout, it should not extend standart FOSUser layout, so remove line {% extends 'FOSUserBundle::layout.html.twig' %}. But usually developers make one base layout, in my case it is \app\Resources\views\base.html.twig, so if I want to override fosuser layout I will have in app/Resources/FOSUserBundle/views/layout.html.twig something like this

{% extends 'base.html.twig' %}

{% block title %}User Management{% endblock %}

{% block content %}
    {% block fos_user_content %}{% endblock %}
{% endblock %}

在第一行中,您扩展了基本布局,而不是FOSUser.您可能不会扩展某些内容,也许为此模板拥有单独的完整布局.

In first line you extend your base layout not FOSUser. You may not extend something, maybe you have separate complete layout for this template.

这篇关于扩展FOSUserBundle的默认模板layout.html.twig时,Symfony Server崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆