小编iwo*_*oli的帖子

symfony2验证继承

我有一个父实体,它有多个继承其方法的子实体.什么时候验证表单我不知道如何不重复每个父字段验证约束.

这是一些代码:

#validation.yml
Dir\Entity\Parent:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}

Dir\Entity\Child1:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}
        age:
          - NotBlank: {message: 'age.empty'}

Dir\Entity\Child2:
    properties:
        name:
          - NotBlank: {message: 'name.empty'}
        title:
          - NotBlank: {message: 'title.empty'}
Run Code Online (Sandbox Code Playgroud)

如您所见,name属性在子约束中一次又一次地返回.有没有办法直接在子节点中包含父约束,所以我不必重复父约束修改?

提前致谢!

yaml symfony

5
推荐指数
1
解决办法
1298
查看次数

标签 统计

symfony ×1

yaml ×1