简体   繁体   English

Symfony2 FOSUserBundle =>自定义错误

[英]Symfony2 FOSUserBundle => Customize error

I'm developping a website using Symfony2 and FOSUserBundle for the user side. 我正在为用户端使用Symfony2和FOSUserBundle开发一个网站。 I'm trying to customize the registration form, and i'm experimenting some problems. 我正在尝试自定义注册表格,并且正在尝试一些问题。

  1. I tried to follow the doc to include field errors beside the field, but it only show it on the top of the form; 我试图按照该文档在字段旁边添加字段错误,但是它仅在表单顶部显示;
  2. When both passwords aren't the same, there's an error written in the top of the form: The value is not valid. 如果两个密码不同,则在表单顶部会写一个错误:该值无效。 This is not very clear, and I'd like to translate it in french but I can't seem to find it in the language files. 这不是很清楚,我想将其翻译成法语,但似乎在语言文件中找不到。 I used to translate all the forms, except that error. 我曾经翻译过所有表格,除了那个错误。

Here is my fields template: 这是我的字段模板:

{% block field_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<ul class="list_error">
{% for error in errors %}
<li>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock field_errors %}


{% block field_row %}
{% spaceless %}
<tr>
    <td>
        <label for="{{ form.vars.id }}">{{ form.vars.id|trans( {}, "FOSUserBundle" ) }}</label>
    </td>
    <td>
        {{ form_widget(form) }}
        {{ form_errors(form) }}
    </td>
</tr>
{% endspaceless %}
{% endblock field_row %}

2.(!) The message is hardcoded in the validation, it seems. 2.(!)消息似乎在验证中被硬编码。 Located in: Vendor/bundles/FOS/UserBundle/Validator/Password.php. 位于:供应商/捆绑/FOS/UserBundle/Validator/Password.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM