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 CTypeValidator

CTypeValidator verifies if the attribute is of the type specified by CTypeValidator::$type.

The following data types are supported:
  • integer A 32-bit signed integer data type.
  • float A double-precision floating point number data type.
  • string A string data type.
  • array An array value.
  • date A date data type.
  • time A time data type.
  • datetime A date and time data type.

For date type, the property CTypeValidator::$dateFormat will be used to determine how to parse the date string. If the given date value doesn't follow the format, the attribute is considered as invalid.

Starting from version 1.1.7, we have a dedicated date validator CDateValidator. Please consider using this validator to validate a date-typed value.

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), CTypeValidator allows for the following placeholders to be specified:
  • {type}: replaced with data type the attribute should be CTypeValidator::$type.
CComponent
Extended by CValidator
Extended by CTypeValidator
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/CTypeValidator.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
public boolean
# validateValue( mixed $value )

Validates a static value. Note that this method does not respect CTypeValidator::$allowEmpty property. This method is provided so that you can call it directly without going through the model validation rule mechanism.

Validates a static value. Note that this method does not respect CTypeValidator::$allowEmpty property. This method is provided so that you can call it directly without going through the model validation rule mechanism.

Parameters

$value
mixed
$value the value to be validated

Returns

boolean
whether the value is valid

Since

1.1.13
Methods inherited from CValidator
addError(), applyTo(), clientValidateAttribute(), 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 $type 'string'
#

the data type that the attribute should be. Defaults to 'string'. Valid values include 'string', 'integer', 'float', 'array', 'date', 'time' and 'datetime'.

the data type that the attribute should be. Defaults to 'string'. Valid values include 'string', 'integer', 'float', 'array', 'date', 'time' and 'datetime'.

public string $dateFormat 'MM/dd/yyyy'
#

the format pattern that the date value should follow. Defaults to 'MM/dd/yyyy'. Please see CDateTimeParser for details about how to specify a date format. This property is effective only when CTypeValidator::$type is 'date'.

the format pattern that the date value should follow. Defaults to 'MM/dd/yyyy'. Please see CDateTimeParser for details about how to specify a date format. This property is effective only when CTypeValidator::$type is 'date'.

public string $timeFormat 'hh:mm'
#

the format pattern that the time value should follow. Defaults to 'hh:mm'. Please see CDateTimeParser for details about how to specify a time format. This property is effective only when CTypeValidator::$type is 'time'.

the format pattern that the time value should follow. Defaults to 'hh:mm'. Please see CDateTimeParser for details about how to specify a time format. This property is effective only when CTypeValidator::$type is 'time'.

public string $datetimeFormat 'MM/dd/yyyy hh:mm'
#

the format pattern that the datetime value should follow. Defaults to 'MM/dd/yyyy hh:mm'. Please see CDateTimeParser for details about how to specify a datetime format. This property is effective only when CTypeValidator::$type is 'datetime'.

the format pattern that the datetime value should follow. Defaults to 'MM/dd/yyyy hh:mm'. Please see CDateTimeParser for details about how to specify a datetime format. This property is effective only when CTypeValidator::$type is 'datetime'.

public boolean $allowEmpty true
#

whether the attribute value can be null or empty. Defaults to true, meaning that if the attribute is empty, it is considered valid.

whether the attribute value can be null or empty. Defaults to true, meaning that if the attribute is empty, it is considered valid.

public boolean $strict false
#

whether the actual PHP type of attribute value should be checked. Defaults to false, meaning that correctly formatted strings are accepted for integer and float validators.

whether the actual PHP type of attribute value should be checked. Defaults to false, meaning that correctly formatted strings are accepted for integer and float validators.

Since

1.1.13
Properties inherited from CValidator
$attributes, $builtInValidators, $enableClientValidation, $except, $message, $on, $safe, $skipOnError
API documentation generated by ApiGen 2.8.0