【发布时间】:2014-02-10 15:34:05
【问题描述】:
我正在尝试使用 validation.yml 架构验证集合字段中的实体,但它不起作用。我已经尝试了两种方式。
第一种方法是使用集合约束,但集合字段让我发现缺少某些字段。
第二种方法(我认为最好的方法)是尝试使用“有效”约束来验证集合中的每个对象,但这也不起作用。
在这两种情况下,我都在默认表单选项中设置了“cascade_validation”。
那么,我如何验证集合字段中的实体?
这是我的验证码:
#
# Edition
#
Talim\ActivityBundle\Entity\Edition:
properties:
activity:
- NotNull: ~
accommodation:
- NotNull:
turns:
- Valid: ~
services:
- Count:
min: 1
services:
- Count:
min: 1
childRatio:
- NotBlank: ~
- Type:
type: integer
- GreaterThan:
value: 1
minAge:
- NotBlank: ~
- Type:
type: integer
- GreaterThan:
value: 0
maxAge:
- NotBlank: ~
- Type:
type: integer
- LessThan:
value: 35
specialNeeds:
- NotNull: ~
- Type:
type: bool
largeFamily:
- NotNull: ~
- Type:
type: bool
#
# Turn
#
Talim\ActivityBundle\Entity\Turn:
startAt:
- NotBlank: ~
- Type:
type: string
- Date: ~
endAt:
- NotBlank: ~
- Type:
type: string
- Date: ~
minPlaces:
- NotBlank: ~
- Type:
type: string
totalPlaces:
- NotBlank: ~
- Type:
type: integer
- GreaterThan:
value: 1
【问题讨论】:
-
您的实体文件中是否还有验证注释?您是否设置了其他验证组?
-
我会建议你,在你的实体中使用注释,它会给你完美的结果。谢谢
-
你是说这是yaml的问题吗?我在整个项目中使用它
标签: php validation symfony