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
 1: <?php
 2: /**
 3:  * CInlineValidator class file.
 4:  *
 5:  * @author Qiang Xue <qiang.xue@gmail.com>
 6:  * @link http://www.yiiframework.com/
 7:  * @copyright 2008-2013 Yii Software LLC
 8:  * @license http://www.yiiframework.com/license/
 9:  */
10: 
11: /**
12:  * CInlineValidator represents a validator which is defined as a method in the object being validated.
13:  *
14:  * @author Qiang Xue <qiang.xue@gmail.com>
15:  * @package system.validators
16:  * @since 1.0
17:  */
18: class CInlineValidator extends CValidator
19: {
20:     /**
21:      * @var string the name of the validation method defined in the active record class
22:      */
23:     public $method;
24:     /**
25:      * @var array additional parameters that are passed to the validation method
26:      */
27:     public $params;
28:     /**
29:      * @var string the name of the method that returns the client validation code (See {@link clientValidateAttribute}).
30:      */
31:     public $clientValidate;
32: 
33:     /**
34:      * Validates the attribute of the object.
35:      * If there is any error, the error message is added to the object.
36:      * @param CModel $object the object being validated
37:      * @param string $attribute the attribute being validated
38:      */
39:     protected function validateAttribute($object,$attribute)
40:     {
41:         $method=$this->method;
42:         $object->$method($attribute,$this->params);
43:     }
44: 
45:     /**
46:      * Returns the JavaScript code needed to perform client-side validation by calling the {@link clientValidate} method.
47:      * In the client validation code, these variables are predefined:
48:      * <ul>
49:      * <li>value: the current input value associated with this attribute.</li>
50:      * <li>messages: an array that may be appended with new error messages for the attribute.</li>
51:      * <li>attribute: a data structure keeping all client-side options for the attribute</li>
52:      * </ul>
53:      * <b>Example</b>:
54:      *
55:      * If {@link clientValidate} is set to "clientValidate123", clientValidate123() is the name of
56:      * the method that returns the client validation code and can look like:
57:      * <pre>
58:      * <?php
59:      *   public function clientValidate123($attribute,$params)
60:      *   {
61:      *      if(!isset($params['message']))
62:      *         $params['message']='Value should be 123';
63:      *      $js = "if(value != '123') { messages.push($params['message']); }";
64:      *      return $js;
65:      *   }
66:      * ?>
67:      * </pre>
68:      * @param CModel $object the data object being validated
69:      * @param string $attribute the name of the attribute to be validated.
70:      * @return string the client-side validation script.
71:      * @see CActiveForm::enableClientValidation
72:      * @since 1.1.9
73:      */
74:     public function clientValidateAttribute($object,$attribute)
75:     {
76:         if($this->clientValidate!==null)
77:         {
78:             $method=$this->clientValidate;
79:             return $object->$method($attribute,$this->params);
80:         }
81:     }
82: }
83: 
API documentation generated by ApiGen 2.8.0