Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CBooleanValidator
  • CCaptchaValidator
  • CCompareValidator
  • CDateValidator
  • CDefaultValueValidator
  • CEmailValidator
  • CExistValidator
  • CFileValidator
  • CFilterValidator
  • CInlineValidator
  • CNumberValidator
  • CRangeValidator
  • CRegularExpressionValidator
  • CRequiredValidator
  • CSafeValidator
  • CStringValidator
  • CTypeValidator
  • CUniqueValidator
  • CUnsafeValidator
  • CUrlValidator
  • CValidator
  • X2UrlValidator
  • Overview
  • Package
  • Class
  • Tree

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 the CValidator::$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
Extended by CValidator
Extended by CCompareValidator
Package: system\validators
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
Methods summary
protected
# validateAttribute( CModel $object, string $attribute )

Validates the attribute of the object. If there is any error, the error message is added to the object.

Validates the attribute of the object. If there is any error, the error message is added to the object.

Parameters

$object
CModel
$object the object being validated
$attribute
string
$attribute the attribute being validated

Throws

CException
if invalid operator is used
public string
# clientValidateAttribute( CModel $object, string $attribute )

Returns the JavaScript needed for performing client-side validation.

Returns the JavaScript needed for performing client-side validation.

Parameters

$object
CModel
$object the data object being validated
$attribute
string
$attribute the name of the attribute to be validated.

Returns

string
the client-side validation script.

Throws

CException
if invalid operator is used

Since

1.1.7

See

CActiveForm::$enableClientValidation

Overrides

CValidator::clientValidateAttribute()
Methods inherited from CValidator
addError(), applyTo(), createValidator(), isEmpty(), validate()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public string $compareAttribute
#

the name of the attribute to be compared with

the name of the attribute to be compared with

public string $compareValue
#

the constant value to be compared with

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.

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.

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:
  • '=' or '==': validates to see if the two values are equal. If CCompareValidator::$strict is true, the comparison will be done in strict mode (i.e. checking value type as well).
  • '!=': validates to see if the two values are NOT equal. If CCompareValidator::$strict is true, the comparison will be done in strict mode (i.e. checking value type as well).
  • '>': validates to see if the value being validated is greater than the value being compared with.
  • '>=': validates to see if the value being validated is greater than or equal to the value being compared with.
  • '<': validates to see if the value being validated is less than the value being compared with.
  • '<=': validates to see if the value being validated is less than or equal to the value being compared with.
the operator for comparison. Defaults to '='. The followings are valid operators:
  • '=' or '==': validates to see if the two values are equal. If CCompareValidator::$strict is true, the comparison will be done in strict mode (i.e. checking value type as well).
  • '!=': validates to see if the two values are NOT equal. If CCompareValidator::$strict is true, the comparison will be done in strict mode (i.e. checking value type as well).
  • '>': validates to see if the value being validated is greater than the value being compared with.
  • '>=': validates to see if the value being validated is greater than or equal to the value being compared with.
  • '<': validates to see if the value being validated is less than the value being compared with.
  • '<=': validates to see if the value being validated is less than or equal to the value being compared with.
Properties inherited from CValidator
$attributes, $builtInValidators, $enableClientValidation, $except, $message, $on, $safe, $skipOnError
API documentation generated by ApiGen 2.8.0