覆盖FOS用户包的 "更改密码 "模板[英] Overriding "Change Password" Template from FOS User Bundle

本文是小编为大家收集整理的关于覆盖FOS用户包的 "更改密码 "模板的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我做了一些研究,可悲的是找不到任何帮助.

因此,我将FosuserBundle ChangePasswordation渲染到我的模板中,但它显示了供应商给出的默认模板.

我的模板渲染了控制器:

{% 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 %}

让我发疯的是,我在我的besurout.html.twig中以相同的方式从fosuserbundle渲染登录控制器,并且在那里工作得很好.

布局中的代码段:

{% 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/CACH/DEV'或" App/Cache/prod'.

本文地址:https://www.itbaoku.cn/post/2090823.html

问题描述

I did some research and sadly couldn't find any help for that.

So I'm rendering the FOSUserBundle ChangePasswordAction into a template of mine, but it displays the default template given from the vendor.

My template where the controller is rendered:

{% block body %}
    <h2>Einstellungen</h2>
    <br/>
    <h4>Ändern Sie ihr Passwort</h4>
    {% render controller("FOSUserBundle:ChangePassword:changePassword") %}
{% endblock %}

My template for the ChangePasswordAction, the path is 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 %}

What drives me crazy is that i render the login controller from the FOSUserBundle the same way in my layout.html.twig and it's working perfectly there.

The snippet of code from the layout:

{% block sidebar %}
    {% render controller("FOSUserBundle:Security:Login") %}
{% endblock %}

and the 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 %}

Am i missing something or what am i doing wrong so i can't override the changePassword Template?

推荐答案

Moving from comments to an answer:

Have you cleared your cache since adding the new template?

其他推荐答案

What you basically do is you create a user bundle of your own + set it's parent to the FOS user bundle. (You should already have done this step)

Then you set the template in: MyCompany/MyProject/UserBundle/Resources/views/Resetting/request.html.twig

Because of the fact that the file in the FOS user bundle is on the same place, your file will overwrite that template.

其他推荐答案

If you think you've done everything correctly and still it doesn't work, you can try to clear the cache with a Symfony command in the terminal, or in some cases manually delete the cache directories - 'app/cache/dev' or 'app/cache/prod'.