Class CCompareValidator
CCompareValidator compares the specified attribute value with another value and validates if they are equal.
The value being compared with can be another attribute value (specified via
CCompareValidator::$compareAttribute
) or a constant (specified via CCompareValidator::$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.
The comparison can be either CCompareValidator::$strict
or not.
CCompareValidator supports different comparison operators. Previously, it only compares to see if two values are equal or not.
When using theCValidator::$message
property to define a custom error message, the
message may contain additional placeholders that will be replaced with the
actual content. In addition to the "{attribute}" placeholder, recognized by all
validators (see CValidator
), CCompareValidator allows for the following
placeholders to be specified:
- {compareValue}: replaced with the constant value being compared with (
CCompareValidator::$compareValue
). - {compareAttribute}: replaced with the label of the attribute being compared
with (
CCompareValidator::$compareAttribute
).
- CComponent
- CValidator
- CCompareValidator
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/validators/CCompareValidator.php
protected
|
#
validateAttribute(
Validates the attribute of the object. If there is any error, the error message is added to the object. |
public
string
|
#
clientValidateAttribute(
Returns the JavaScript needed for performing client-side validation. |
addError(),
applyTo(),
createValidator(),
isEmpty(),
validate()
|
public
string
|
$compareAttribute |
|
#
the name of the attribute to be compared with |
public
string
|
$compareValue |
|
#
the constant value to be compared with |
public
boolean
|
$strict | false |
#
whether the comparison is strict (both value and type must be the same.) Defaults to false. |
public
boolean
|
$allowEmpty | false |
#
whether the attribute value can be null or empty. Defaults to false. If this is true, it means the attribute is considered valid when it is empty. |
public
string
|
$operator | '=' |
#
the operator for comparison. Defaults to '='. The followings are valid
operators:
|
$attributes,
$builtInValidators,
$enableClientValidation,
$except,
$message,
$on,
$safe,
$skipOnError
|