问题描述
我想在 Symfony 中添加一个带有注释的约束,以便日期落在该范围内,但无法使用 min 明确指定此范围.和最大.年份应介于当前年份(减去当前年份或数字)和指示的最小值之间.例如,如果我现在输入一个日期必须在 2010/1960 之间,但 2010 应该是从当前年 10 获得的.这可以在 Symfony 中以任何方式完成吗?
I want to add a constraint with annotation in Symfony for a date falls within the range, but this range can not be specified explicitly with min. and max. The year should be between the current year (by subtracting the current year or number) and the minimum indicated. For example, if I type a date now must be between 2010/1960, but 2010 should be obtained from the current year-10. This can be done in any way in Symfony?
推荐答案
是的,这是可能的,您应该按照此处的说明创建自定义验证约束:
Yes it is possible, you should create a custom validation constraint as explained here :
http://symfony.com/doc/current/cookbook/validation/custom_constraint.html
这篇关于使用 Symfony2 进行日期范围验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!