Symfony2 Validator消息依赖于组

时间:2014-06-03 06:45:39

标签: symfony yaml symfony-forms

我有一个像这样的通用验证器来添加用户和patien详细信息

# src/Acme/DemoBundle/Resources/config/validator.yml 
Acme\DemoBundle\Entity\contact:
    properties:
        lastName:
            - NotBlank:
                groups: [adduser, addpatient]
                message: Last Name Should not be blank

我需要的是为不同的组显示不同的验证器消息,如

for adduser

User Name Should not be blank

对于addpatient

Patient Name Should not be blank

我试过

Acme\DemoBundle\Entity\contact:
    properties:
        lastName:
            - NotBlank:
                groups: adduser
                message: User Name Should not be blank
                groups: addpatient
                message: Patient Name Should not be blank

以及

Acme\DemoBundle\Entity\contact:
    properties:
        lastName:
            - NotBlank:
                groups: adduser
                message: User Name Should not be blank
        lastName:
            - NotBlank:
                groups: addpatient
                message: Patient Name Should not be blank

1 个答案:

答案 0 :(得分:4)

尝试:

Acme\DemoBundle\Entity\contact:
    properties:
        lastName:
            - NotBlank:
                groups: adduser
                message: User Name Should not be blank
            - NotBlank:
                groups: addpatient
                message: Patient Name Should not be blank