Class hscstudio\heart\helpers\DateTimeCompareValidator

Inheritancehscstudio\heart\helpers\DateTimeCompareValidator » yii\validators\Validator
Available since version2.0

CompareValidator compares the specified attribute value with another value.

The value being compared with can be another attribute value (specified via $compareAttribute) or a constant (specified via $compareValue. When both are specified, the latter takes precedence. If neither is specified, the attribute will be compared with another attribute whose name is by appending "_repeat" to the source attribute name.

CompareValidator supports different comparison operators, specified via the $operator property.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$compareAttribute string The name of the attribute to be compared with. hscstudio\heart\helpers\DateTimeCompareValidator
$compareValue mixed The constant value to be compared with. hscstudio\heart\helpers\DateTimeCompareValidator
$message string The user-defined error message. hscstudio\heart\helpers\DateTimeCompareValidator
$operator string The operator for comparison. hscstudio\heart\helpers\DateTimeCompareValidator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
compareValues() Compares two values with the specified operator. hscstudio\heart\helpers\DateTimeCompareValidator

Property Details

$compareAttribute public property

The name of the attribute to be compared with. When both this property and $compareValue are set, the latter takes precedence. If neither is set, it assumes the comparison is against another attribute whose name is formed by appending '_repeat' to the attribute being validated. For example, if 'password' is being validated, then the attribute to be compared would be 'password_repeat'.

See also $compareValue.

$compareValue public property
mixed $compareValue null

The constant value to be compared with. When both this property and $compareAttribute are set, this property takes precedence.

See also $compareAttribute.

$message public property

The user-defined error message. It may contain the following placeholders which will be replaced accordingly by the validator:

  • {attribute}: the label of the attribute being validated
  • {value}: the value of the attribute being validated
  • {compareValue}: the value or the attribute label to be compared with
  • {compareAttribute}: the label of the attribute to be compared with
$operator public property

The operator for comparison. 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.

Method Details

compareValues() protected method

Compares two values with the specified operator.

boolean compareValues$operator$value$compareValue )
$operator string

The comparison operator

$value mixed

The value being compared

$compareValue mixed

Another value being compared

return boolean

Whether the comparison using the specified operator is true.

init() public method

void init( )
validateAttribute() public method

void validateAttribute$object$attribute )
$object
$attribute