UniqueEntity 约束不显示消息
我正在我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论