empathy / yii2-datetime-compare
DateTime比较验证器
v2.2.1
2016-02-24 06:08 UTC
Requires
- bower-asset/moment: ^2.11
README
为Yii Framework 2.0提供的DateTime比较验证器。在实现此增强功能之前,这是一个临时解决方案。
[[Empathy\Validators\DateTimeCompareValidator|compare]]
[ // validates if the value of "birthday" attribute equals to that of "birthday_repeat" ['birthday', DateTimeCompareValidator::className()], // validates if birthday is less than or equal to today ['birthday', DateTimeCompareValidator::className(), 'compareValue' => date('Y-m-d H:i:s'), 'operator' => '<='], // validates if birthday is less than driver's license expiry ['birthday', DateTimeCompareValidator::className(), 'compareAttribute' => 'driver_license_expiry', 'operator' => '<'], ]
此验证器比较指定的输入日期时间与另一个日期时间,并确保它们的关系符合由operator
属性指定的关系。
compareAttribute
:应比较其值的属性名称。当验证器用于验证属性时,此属性的默认值将是属性名称后缀为_repeat
的名称。例如,如果正在验证的属性是birthday
,则此属性将默认为birthday_repeat
。compareValue
:应与输入值比较的常量值。当同时指定了此属性和compareAttribute
时,此属性将具有优先级。operator
:比较运算符。默认为==
,表示检查输入值是否等于compareAttribute
或compareValue
的值。支持以下运算符:==
:检查两个值是否相等。比较以非严格模式进行。===
:检查两个值是否相等。比较以严格模式进行。!=
:检查两个值是否不相等。比较以非严格模式进行。!==
:检查两个值是否不相等。比较以严格模式进行。>
:检查正在验证的值是否大于比较值。>=
:检查正在验证的值是否大于或等于比较值。<
:检查正在验证的值是否小于比较值。<=
:检查正在验证的值是否小于或等于比较值。
format
:用于解析值的日期格式。如果为空,PHP Date将尝试猜测您的格式。jsFormat
:客户端解析值的日期格式。如果为空,Moment.js将尝试猜测您的格式。Moment.js无法正确猜测所有格式,并且此功能将在Moment.js的未来版本中弃用。请参阅moment/moment#1407
安装
安装此扩展的首选方式是通过composer。
注意:请检查此扩展的composer.json,以获取此扩展的要求和依赖关系。
运行
$ composer require empathy/yii2-datetime-compare