Difference between #2 and #1 of Reference: Model rules validation

unchanged
Title
Reference: Model rules validation
unchanged
Category
Tutorials
unchanged
Tags
changed
Content
This is a reference to be used for Model rule validation. The
documentationvalidation and is compiled from the Yii
documentation and code. The purpose is to have all the information gathered in
one place instead of scattered. This reference is not an intro.

Applys to Yii: 1.0.10

## How validation works
The [CModel](/doc/api/1.0.10/CModel) class uses a method named
[rules](/doc/api/1.0.10/CModel#rules-detail) to return an array with the rules
for validation.

To~~~
[php]
public function rules()
{
    return array(
        array('username, password', 'required'),
        array('password_repeat', 'required', 'on'=>'register'),
        array('password', 'compare', 'on'=>'register'),
    );
}
~~~

The code above is an example of what the [rules()](/doc/api/CModel#rules-detail)
function may look like. The arrays in the main array each one sets a rule of
validation. 

### Choise of validators

Yii will look for validators in the specifik order:

1. A method in the model class with the same name as the validator specified.
2. A builtin validator in Yii that extends the CValidator class.
3. A path/alias to a home made  CValidator class that is not built in.

### Scenarios

TODO: Write shortly about scenarios.

### Standard parameters

~~~
[php]
array(
	'attribute list', 
	'validator name', 
	'on'=>'scenario name', 
	'message'=>'The attribute didn\'t validate!', 
	...validation parameters...
);
~~~

+ <code>attribute list</code>: specifies the attributes (separated
by commas) to be continuedvalidated;
+ <code>validator name</code>: specifies the validator to be used.
+ <code>on</code>: this specifies the scenarios when the validation
rule should be performed. Separate different scenarios with commas. If this
option is not set, the rule will be applied in any scenario.
+ <code>message</code>: Error message if validation fails.
+ <code>...validation parameters...</code>: any number of extra
parameters to be used by the specified validator.

## Validation rules reference

TODO: Write all references+ <code>boolean</code> :
[CBooleanValidator](/doc/api/CBooleanValidator)
+ <code>captcha</code> :
[CCaptchaValidator](/doc/api/CCaptchaValidator)
+ <code>compare</code> :
[CCompareValidator](/doc/api/CCompareValidator)
+ <code>default</code> :
[CDefaultValueValidator](/doc/api/CDefaultValueValidator)
+ <code>email</code> : [CEmailValidator](/doc/api/CEmailValidator)
+ <code>exists</code> : [CExistValidator](/doc/api/CExistValidator)
+ <code>file</code> : [CFileValidator](/doc/api/CFileValidator)
+ <code>filter</code> :
[CFilterValidator](/doc/api/CFilterValidator)
+ <code>in</code> : [CRangeValidator](/doc/api/CRangeValidator)
+ <code>length</code> :
[CStringValidator](/doc/api/CStringValidator)
+ <code>numerical</code> :
[CNumberValidator](/doc/api/CNumberValidator)
+ <code>match</code> :
[CRegularExpressionValidator](/doc/api/CRegularExpressionValidator)
+ <code>required</code> :
[CRequiredValidator](/doc/api/CRequiredValidator), validates that the specified
attribute does not have null or empty value.
+ <code>safe</code> : [CSafeValidator](/doc/api/CSafeValidator)
+ <code>type</code> : [CTypeValidator](/doc/api/CTypeValidator)
+ <code>unique</code> :
[CUniqueValidator](/doc/api/CUniqueValidator)
+ <code>unsafe</code> :
[CUnsafeValidator](/doc/api/CUnsafeValidator)
+ <code>url</code> : [CUrlValidator](/doc/api/CUrlValidator)

## Selected readings
[The Definitive Guide to Yii: Working with Forms - Creating
Model](/doc/guide/form.model)<br />
[Yii PHP Framework Class Reference -
CValidator](/doc/api/CValidator)[CModel::validate()](/doc/api/CModel#validate-detail)<br
/>
[CModel::rules()](/doc/api/CModel#rules-detail)<br />
[CModel::$scenario](/doc/api/CModel#scenario-detail)<br />
[CValidator](/doc/api/CValidator)<br />
[CInlineValidator](/doc/api/CInlineValidator)

### Built in validators in Yii
[CBooleanValidator](/doc/api/CBooleanValidator)<br />
[CCaptchaValidator](/doc/api/CCaptchaValidator)<br />
[CCompareValidator](/doc/api/CCompareValidator)<br />
[CDefaultValueValidator](/doc/api/CDefaultValueValidator)<br />
[CEmailValidator](/doc/api/CEmailValidator)<br />
[CExistValidator](/doc/api/CExistValidator)<br />
[CFileValidator](/doc/api/CFileValidator)<br />
[CFilterValidator](/doc/api/CFilterValidator)<br />
[CInlineValidator](/doc/api/CInlineValidator)<br />
[CNumberValidator](/doc/api/CNumberValidator)<br />
[CRangeValidator](/doc/api/CRangeValidator)<br />
[CRegularExpressionValidator](/doc/api/CRegularExpressionValidator)<br />
[CRequiredValidator](/doc/api/CRequiredValidator)<br />
[CSafeValidator](/doc/api/CSafeValidator)<br />
[CStringValidator](/doc/api/CStringValidator)<br />
[CTypeValidator](/doc/api/CTypeValidator)<br />
[CUniqueValidator](/doc/api/CUniqueValidator)<br />
[CUnsafeValidator](/doc/api/CUnsafeValidator)<br />
[CUrlValidator](/doc/api/CUrlValidator)