PHP Класс yii\validators\CompareValidator

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. The default comparison function is based on string values, which means the values are compared byte by byte. When comparing numbers, make sure to set the [[$type]] to [[TYPE_NUMBER]] to enable numeric comparison.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends Validator
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$compareAttribute 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'.
$compareValue the constant value to be compared with. When both this property and [[compareAttribute]] are set, this property takes precedence.
$message 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 - {compareValueOrAttribute}: the value or the attribute label to be compared with
$operator 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. When you want to compare numbers, make sure to also set [[type]] to number.
$type the type of the values being compared. The follow types are supported: - [[TYPE_STRING|string]]: the values are being compared as strings. No conversion will be done before comparison. - [[TYPE_NUMBER|number]]: the values are being compared as numbers. String values will be converted into numbers before comparison.

Открытые методы

Метод Описание
clientValidateAttribute ( $model, $attribute, $view )
init ( )
validateAttribute ( $model, $attribute )

Защищенные методы

Метод Описание
compareValues ( string $operator, string $type, mixed $value, mixed $compareValue ) : boolean Compares two values with the specified operator.
validateValue ( $value )

Описание методов

clientValidateAttribute() публичный Метод

public clientValidateAttribute ( $model, $attribute, $view )

compareValues() защищенный Метод

Compares two values with the specified operator.
protected compareValues ( string $operator, string $type, mixed $value, mixed $compareValue ) : boolean
$operator string the comparison operator
$type string the type of the values being compared
$value mixed the value being compared
$compareValue mixed another value being compared
Результат boolean whether the comparison using the specified operator is true.

init() публичный Метод

public init ( )

validateAttribute() публичный Метод

public validateAttribute ( $model, $attribute )

validateValue() защищенный Метод

protected validateValue ( $value )

Описание свойств

$compareAttribute публичное свойство

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'.
См. также: compareValue
public $compareAttribute

$compareValue публичное свойство

the constant value to be compared with. When both this property and [[compareAttribute]] are set, this property takes precedence.
См. также: compareAttribute
public $compareValue

$message публичное свойство

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 - {compareValueOrAttribute}: the value or the attribute label to be compared with
public $message

$operator публичное свойство

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. When you want to compare numbers, make sure to also set [[type]] to number.
public $operator

$type публичное свойство

the type of the values being compared. The follow types are supported: - [[TYPE_STRING|string]]: the values are being compared as strings. No conversion will be done before comparison. - [[TYPE_NUMBER|number]]: the values are being compared as numbers. String values will be converted into numbers before comparison.
public $type