没有识别Symfony表单form_rest块

时间:2015-12-22 11:20:33

标签: php symfony twig twig-extension

我正在使用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包含在其中。

1 个答案:

答案 0 :(得分:1)

我假设你有一个自定义表单来添加你自己的字段。我遇到了同样的问题,并发现扩展fosuserbundle的注册表单的方式在sf 2.8中有所改变。查看文档:

http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html

相关问题