定制 gerpayt/yii2-datetime-compare 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gerpayt/yii2-datetime-compare

最新稳定版本:v1.0.0

Composer 安装命令:

composer require gerpayt/yii2-datetime-compare

包简介

DateTime comparison validator

README 文档

README

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads

DateTime comparison validator for Yii Framework 2.0. Temporary solution until this enhancement is implemented.

[[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' => '<'],
]

This validator compares the specified input datetime with another one and make sure if their relationship is as specified by the operator property.

  • compareAttribute: the name of the attribute whose value should be compared with. When the validator is being used to validate an attribute, the default value of this property would be the name of the attribute suffixed with _repeat. For example, if the attribute being validated is birthday, then this property will default to birthday_repeat.
  • compareValue: a constant value that the input value should be compared with. When both of this property and compareAttribute are specified, this property will take precedence.
  • operator: the comparison operator. Defaults to ==, meaning checking if the input value is equal to that of compareAttribute or compareValue. The following operators are supported:
    • ==: check if two values are equal. The comparison is done is non-strict mode.
    • ===: check if two values are equal. The comparison is done is strict mode.
    • !=: check if two values are NOT equal. The comparison is done is non-strict mode.
    • !==: check if two values are NOT equal. The comparison is done is strict mode.
    • >: check if value being validated is greater than the value being compared with.
    • >=: check if value being validated is greater than or equal to the value being compared with.
    • <: check if value being validated is less than the value being compared with.
    • <=: check if value being validated is less than or equal to the value being compared with.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies.

Either run

$ php composer.phar require EAnushan/yii2-datetime-compare "*"

or add

"EAnushan/yii2-datetime-compare": "*"

to the require section of your composer.json file.

统计信息

  • 总下载量: 41
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2015-05-13