是否有办法在symfony验证器的单个属性值上验证UniqueEntity?
# Acme\Resources\config\validation.yml
Acme\DemoBundle\Entity\User:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: username, message: This username is already taken}
properties:
username:
- NotBlank: { message: You must provide a username}
当我在“用户注册”表单上运行验证时,它运行正常,检查NotBlank
然后UniqueEntity
并举报违规行为。
但是,我还使用验证器和validatePropertyValue
对每个字段(作为用户类型)运行ajax验证,如下所示:
$violations = $this->validator->validatePropertyValue("Acme\DemoBundle\Entity\User", "username", $value);
var_dump($violations);
只检查属性用户名约束。它永远不会检查uniqueEntity
约束。