正如标题所示,我试图用我自己的模板来定制FOSUserBundle的模板。但它根本不起作用。我尝试了所有发现的帖子,校正了所有内容,清除了数千次缓存,仍然无法使用。从继承覆盖FOSUserBundle的模板
捆绑类的getParent:
<?php
// src/PLL/UserBundle/PLLUserBundle.php
namespace PLL\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class PLLUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
?>
模板应该覆盖FOS'之一:
{# src/PLL/UserBundle/Resources/views/layout.html.twig #}
{% extends "PLLCoreBundle::layout.html.twig" %}
{% block body %}
{% for key, messages in app.session.flashbag.all() %}
{% for message in messages %}
<div class="alert alert-{{ key }}">
{{ message|trans({}, 'FOSUserBundle') }}
</div>
{% endfor %}
{% endfor %}
{% block fos_user_content %}
{% endblock fos_user_content %}
{% endblock %}
FOS”模板,那实际上是正在使用的Symfony的一个:
{# vendor/friendsofsymfony/user-bundle/Resources/views/layout.html.twig #}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} |
<a href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
{% else %}
<a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a>
{% endif %}
</div>
{% if app.request.hasPreviousSession %}
{% for type, messages in app.session.flashbag.all() %}
{% for message in messages %}
<div class="flash-{{ type }}">
{{ message }}
</div>
{% endfor %}
{% endfor %}
{% endif %}
<div>
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
</body>
</html>
去/web/app_dev.php/login仍然显示FOS的布局,即使在删除缓存后再来一遍。无论是使用php bin/console缓存:清除,还是“手动”删除项目根目录下的var文件夹。甚至删除了我的浏览器的缓存。
更何况,扩展“PLLCoreBundle :: layout.html.twig”在我网站上的任何其他视图中完美无缺。所以我不认为它来自我的树枝模板中的错误。
情况下,他们可以帮上什么忙,
我security.yml文件:
// app/config/security.yml
security:
[...]
firewalls:
main:
pattern: ^/
anonymous: true
provider: main
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
logout:
path: fos_user_security_logout
target: /platform
[...]
应用程序的路由文件:
// app/config/routing.yml
[...]
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
所以......我在想什么?
http://stackoverflow.com/questions/41572723/symfony-3-fosuserbundle-overriding-template – Aerendir
但是,模板不工作或只有一个?我不明白 – Aerendir
@Aerendir FOSUserBundle的默认模板正在工作。我的网站上的其他所有模板都在工作。唯一不能工作的是我的自定义模板不能覆盖FOS的模板,所以当我想进入我的/登录页面或/注册时,我总是会到达FOS的模板,无法让我的工作。 – Kishlin