我做了一些调查,遗憾的是没有找到任何帮助。
所以我将FOSUserBundle ChangePasswordAction渲染到我的一个模板中,但它显示的是供应商给出的默认模板。
渲染控制器的模板:
{% block body %}
<h2>Einstellungen</h2>
<br/>
<h4>Ändern Sie ihr Passwort</h4>
{% render controller("FOSUserBundle:ChangePassword:changePassword") %}
{% endblock %}
我的ChangePasswordAction模板,路径是app/Resources/FOSUserBundle/views/ChangePassword/changePassword.html.twig
:
{% block fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
{{ form_start(form) }}
{{ form_errors(form) }}
<p><span class="edit_left_date">{{ form_label(form.current_password, 'Jetziges Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.current_password) }}</span></p>
<p><span class="edit_left_date">{{ form_label(form.new_password, 'Neues Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.new_password) }}</span></p>
<p><span class="edit_left_date">{{ form_label(form.new_password_confirmation 'Bestätigen Sie ihr neues Passwort') }} </span>
<span class="edit_right">{{ form_widget(form.new_password_confirmation) }}</span></p>
<div>
<input type="submit" value="{{ 'Speichern'|trans }}" />
</div>
{{ form_end(form) }}
</form>
{% endblock %}
让我疯狂的是,我从FOSUserBundle中以同样的方式渲染登录控制器在我的layout.html.twig中,它在那里工作得很好。
来自布局的代码片段:
{% block sidebar %}
{% render controller("FOSUserBundle:Security:Login") %}
{% endblock %}
和app/Resources/FOSUserBundle/views/Security/login.html.twig
:
{% block fos_user_content %}
<div class="teaser-header">Login</div>
<form role="form" action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<div class="form-group">
<label for="username">{{ 'MyLog Username'|trans }}</label>
<input class="form-control" type="text" id="username" name="_username" placeholder="Your Username" required="required" />
</div>
<div class="form-group">
<label for="password">{{ 'Password'|trans }}</label>
<input class="form-control" type="password" id="password" name="_password" placeholder="Your Password" required="required" />
</div>
<input type="submit" id="_submit" name="_submit" value="{{ 'Segel setzen'|trans }}" />
<a id="passwordForget" href={{ path('fos_user_resetting_request') }}>Password vergessen?</a>
</form>
{% endblock %}
我错过了什么或者我做错了什么,所以我不能覆盖changePassword
模板?
从注释到答案:
添加新模板后是否清除了缓存?
基本上你要做的就是创建一个你自己的用户包+将它的父节点设置为FOS用户包。(你应该已经完成了这一步)
然后将模板设置为:MyCompany/MyProject/UserBundle/Resources/views/Resetting/request.html.twig
由于FOS用户包中的文件位于同一位置,因此您的文件将覆盖该模板。
如果你认为你已经做了正确的一切,但仍然不能工作,你可以尝试在终端中使用Symfony命令清除缓存,或者在某些情况下手动删除缓存目录- 'app/cache/dev'或'app/cache/prod'。