gerpayt / yii2-datetime-compare
日期时间比较验证器
v1.0.0
2015-02-26 20:02 UTC
This package is not auto-updated.
Last update: 2024-09-28 17:38:31 UTC
README
为 Yii Framework 2.0 提供的日期时间比较验证器。在实现此增强功能之前,这是一个临时解决方案。
[[EAnushan\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。支持以下运算符:==:检查两个值是否相等。比较以非严格模式进行。===:检查两个值是否相等。比较以严格模式进行。!=:检查两个值是否不相等。比较以非严格模式进行。!==:检查两个值是否不相等。比较以严格模式进行。>:检查正在验证的值是否大于比较值。>=:检查正在验证的值是否大于或等于比较值。<:检查正在验证的值是否小于比较值。<=:检查正在验证的值是否小于或等于比较值。
安装
安装此扩展的首选方法是使用 composer。
注意:请检查此扩展的需求和依赖项的 composer.json。
运行以下命令之一:
$ php composer.phar require EAnushan/yii2-datetime-compare "*"
或
"EAnushan/yii2-datetime-compare": "*"
将以下内容添加到您的 composer.json 文件的 require 部分中。