我正在将 FosUserBundle 用于应用程序。我正在覆盖 ( app/Resources/FOSUserbundle/views/Registration/register.html.twig
) 内的注册模板。
register.html.twig
{% extends 'base.html.twig' %}
{% form_theme form '@FOSUser/Form/register_theme.html.twig' %}
{% block body %}
...
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
...
{{ form_rest(form) }}
//this is just for testing since form_end contains form_rest
//inside of it if you have a look at form_div_layout.html.twig.
{{ form_end(form) }}
...
{% endblock body %}
并包含一个 form_theme 文件,我在其中更改了 2 个块(与此问题无关)
register_theme.html.twig
{% extends "form_div_layout.html.twig" %}
{% block form_widget_simple %}
//some code here
{% endblock form_widget_simple %}
问题是在 2.8 更新之前一切正常(我仍然认为这与此无关,但也许我什么也没看到)。
因此,当我尝试使用 form_rest 时,出现以下错误:
An exception has been thrown during the rendering of a template ("Unable to render the form as none of the following blocks exist: "_fos_user_registration_form_rest", "fos_user_registration_rest", "fos_user_registration_rest", "form_rest".") in FOSUserBundle:Registration:register.html.twig at line xx
如果我不使用 form_rest,则缺少 csrf 令牌,我无法完成注册。如果我只使用 form_end 仍然会产生错误,因为 form_rest 包含在其中。