Symfony 2 - Set UniqueEntity message

2019-07-21 05:30发布

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

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

1条回答
The star\"
2楼-- · 2019-07-21 05:49

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
查看更多
登录 后发表回答