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 CValidator

CValidator is the base class for all validators.

Child classes must implement the CValidator::validateAttribute() method.

When using CValidator::createValidator() to create a validator, the following aliases are recognized as the corresponding built-in validator classes:
  • required: CRequiredValidator
  • filter: CFilterValidator
  • match: CRegularExpressionValidator
  • email: CEmailValidator
  • url: CUrlValidator
  • unique: CUniqueValidator
  • compare: CCompareValidator
  • length: CStringValidator
  • in: CRangeValidator
  • numerical: CNumberValidator
  • captcha: CCaptchaValidator
  • type: CTypeValidator
  • file: CFileValidator
  • default: CDefaultValueValidator
  • exist: CExistValidator
  • boolean: CBooleanValidator
  • date: CDateValidator
  • safe: CSafeValidator
  • unsafe: CUnsafeValidator
CComponent
Extended by CValidator

Direct known subclasses

CBooleanValidator, CCaptchaValidator, CNumberValidator, CRangeValidator, CRegularExpressionValidator, CRequiredValidator, CSafeValidator, CStringValidator, CTypeValidator, CUniqueValidator, CUnsafeValidator, CUrlValidator, CCompareValidator, ValidLinkValidator, X2Validator, CDateValidator, CDefaultValueValidator, CEmailValidator, CExistValidator, CFileValidator, CFilterValidator, CInlineValidator

Indirect known subclasses

ArrayValidator, ModuleModelNameValidator, RequiredIfNotSetValidator, X2ModelForeignKeyValidator, X2ModelUniqueIndexValidator, X2UrlValidator
Abstract
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/CValidator.php
Methods summary
abstract protected
# validateAttribute( CModel $object, string $attribute )

Validates a single attribute. This method should be overridden by child classes.

Validates a single attribute. This method should be overridden by child classes.

Parameters

$object
CModel
$object the data object being validated
$attribute
string
$attribute the name of the attribute to be validated.
public static CValidator
# createValidator( string $name, CModel $object, mixed $attributes, array $params = array() )

Creates a validator object.

Creates a validator object.

Parameters

$name
string
$name the name or class of the validator
$object
CModel
$object the data object being validated that may contain the inline validation method
$attributes
mixed
$attributes list of attributes to be validated. This can be either an array of the attribute names or a string of comma-separated attribute names.
$params
array
$params initial values to be applied to the validator properties

Returns

CValidator
the validator
public
# validate( CModel $object, array $attributes = null )

Validates the specified object.

Validates the specified object.

Parameters

$object
CModel
$object the data object being validated
$attributes
array
$attributes the list of attributes to be validated. Defaults to null, meaning every attribute listed in CValidator::$attributes will be validated.
public string
# clientValidateAttribute( CModel $object, string $attribute )
Returns the JavaScript needed for performing client-side validation. Do not override this method if the validator does not support client-side validation. Two predefined JavaScript variables can be used:
  • value: the value to be validated
  • messages: an array used to hold the validation error messages for the value
Returns the JavaScript needed for performing client-side validation. Do not override this method if the validator does not support client-side validation. Two predefined JavaScript variables can be used:
  • value: the value to be validated
  • messages: an array used to hold the validation error messages for the value

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. Null if the validator does not support client-side validation.

Since

1.1.7

See

CActiveForm::$enableClientValidation
public boolean
# applyTo( string $scenario )
Returns a value indicating whether the validator applies to the specified scenario. A validator applies to a scenario as long as any of the following conditions is met:
  • the validator's "on" property is empty
  • the validator's "on" property contains the specified scenario
Returns a value indicating whether the validator applies to the specified scenario. A validator applies to a scenario as long as any of the following conditions is met:
  • the validator's "on" property is empty
  • the validator's "on" property contains the specified scenario

Parameters

$scenario
string
$scenario scenario name

Returns

boolean
whether the validator applies to the specified scenario.
protected
# addError( CModel $object, string $attribute, string $message, array $params = array() )

Adds an error about the specified attribute to the active record. This is a helper method that performs message selection and internationalization.

Adds an error about the specified attribute to the active record. This is a helper method that performs message selection and internationalization.

Parameters

$object
CModel
$object the data object being validated
$attribute
string
$attribute the attribute being validated
$message
string
$message the error message
$params
array
$params values for the placeholders in the error message
protected boolean
# isEmpty( mixed $value, boolean $trim = false )

Checks if the given value is empty. A value is considered empty if it is null, an empty array, or the trimmed result is an empty string. Note that this method is different from PHP empty(). It will return false when the value is 0.

Checks if the given value is empty. A value is considered empty if it is null, an empty array, or the trimmed result is an empty string. Note that this method is different from PHP empty(). It will return false when the value is 0.

Parameters

$value
mixed
$value the value to be checked
$trim
boolean
$trim whether to perform trimming before checking if the string is empty. Defaults to false.

Returns

boolean
whether the value is empty
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 static array $builtInValidators array( 'required'=>'CRequiredValidator', 'filter'=>'CFilterValidator', 'match'=>'CRegularExpressionValidator', 'email'=>'CEmailValidator', 'url'=>'CUrlValidator', 'unique'=>'CUniqueValidator', 'compare'=>'CCompareValidator', 'length'=>'CStringValidator', 'in'=>'CRangeValidator', 'numerical'=>'CNumberValidator', 'captcha'=>'CCaptchaValidator', 'type'=>'CTypeValidator', 'file'=>'CFileValidator', 'default'=>'CDefaultValueValidator', 'exist'=>'CExistValidator', 'boolean'=>'CBooleanValidator', 'safe'=>'CSafeValidator', 'unsafe'=>'CUnsafeValidator', 'date'=>'CDateValidator', )
#

list of built-in validators (name=>class)

list of built-in validators (name=>class)

public array $attributes
#

list of attributes to be validated.

list of attributes to be validated.

public string $message
#

the user-defined error message. Different validators may define various placeholders in the message that are to be replaced with actual values. All validators recognize "{attribute}" placeholder, which will be replaced with the label of the attribute.

the user-defined error message. Different validators may define various placeholders in the message that are to be replaced with actual values. All validators recognize "{attribute}" placeholder, which will be replaced with the label of the attribute.

public boolean $skipOnError false
#

whether this validation rule should be skipped when there is already a validation error for the current attribute. Defaults to false.

whether this validation rule should be skipped when there is already a validation error for the current attribute. Defaults to false.

Since

1.1.1
public array $on
#

list of scenarios that the validator should be applied. Each array value refers to a scenario name with the same name as its array key.

list of scenarios that the validator should be applied. Each array value refers to a scenario name with the same name as its array key.

public array $except
#

list of scenarios that the validator should not be applied to. Each array value refers to a scenario name with the same name as its array key.

list of scenarios that the validator should not be applied to. Each array value refers to a scenario name with the same name as its array key.

Since

1.1.11
public boolean $safe true
#

whether attributes listed with this validator should be considered safe for massive assignment. Defaults to true.

whether attributes listed with this validator should be considered safe for massive assignment. Defaults to true.

Since

1.1.4
public boolean $enableClientValidation true
#

whether to perform client-side validation. Defaults to true. Please refer to CActiveForm::$enableClientValidation for more details about client-side validation.

whether to perform client-side validation. Defaults to true. Please refer to CActiveForm::$enableClientValidation for more details about client-side validation.

Since

1.1.7
API documentation generated by ApiGen 2.8.0