Symfony 2 - 设置UniqueEntity消息 [英] Symfony 2 - Set UniqueEntity message

查看:95
本文介绍了Symfony 2 - 设置UniqueEntity消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有 UniqueEntity 的Symfony 2 / Doctrine 2实体约束。如文档中所示,应该可以设置自定义错误消息。我绑定了以下语法,但这不起作用:

I have a Symfony 2/Doctrine 2 entity with a UniqueEntity constraint. As show in the documentation, it should be possible to set a custom error message. I tied the following syntax, but that dose not work:

/**
 * @ORM\Entity
 * @ORM\Table(name="User")
 * @UniqueEntity("email", message="Your E-Mail adress has already been registered")
 */
class User

UniqueEntity约束消息的正确符号是多少?或者是文件简单的错误?

What is the correct notation for the UniqueEntity constraint message? Or is the documentation simply wrong?

推荐答案

如果您只在这个使用中使用fields选项,它可以用作默认选项(唯一没有名称的选项)。但是,当您指定其他设置时,必须指定字段属性。

If you use only fields option in this annotaion, it can be used as the default option (the only option without name). However when you specify additional settings, you have to specify fields property.

/**
 * @ORM\Entity
 * @ORM\Table(name="User")
 * @UniqueEntity(
 *     fields={"email"},
 *     message="Your E-Mail adress has already been registered"
 * )
 */
class User

这篇关于Symfony 2 - 设置UniqueEntity消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆