UniqueEntity 约束不显示消息

发布于 2025-01-12 01:10:03 字数 922 浏览 2 评论 0原文

我正在我的 App\Entity\User 中实现 UniqueEntity

/**
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
 * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
 */
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
(...)

约束工作正常,如果我尝试在注册表单中复制电子邮件或用户名,表单不会继续并返回到表单。但是当我尝试显示消息时: {{ form_errors(registrationForm) }} 它始终为空。

{{ form_start(registrationForm, {'attr': {'class': 'gap-no read_m span-auto', 'style': 'margin: auto' }}) }}

      {{ form_errors(registrationForm) }}
      
      (...)

      {{ form_row(registrationForm._token) }}
{{ form_end(registrationForm, {'render_rest': false}) }}
     

是不是错了?我如何显示该消息? 我必须在 FormType 中定义其他内容吗?

I'm implementing UniqueEntity in my App\Entity\User:

/**
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
 * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
 */
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
(...)

Constraints work correctly, if I try to duplicate e-mail or username in register form, the form doesn't continue and return me to the form. But when I try to show message with:
{{ form_errors(registrationForm) }} it's always null.

{{ form_start(registrationForm, {'attr': {'class': 'gap-no read_m span-auto', 'style': 'margin: auto' }}) }}

      {{ form_errors(registrationForm) }}
      
      (...)

      {{ form_row(registrationForm._token) }}
{{ form_end(registrationForm, {'render_rest': false}) }}
     

It's wrong? How do I show the message?
Do I have to define something else in the FormType?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文