Difference between #26 and #30 of
Reference: Model rules validation

Changes

Title unchanged

Reference: Model rules validation

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

Form validation, model, validation, reference, validation rules, validator

Content changed

[...]
If this option is not set, the rule will be applied in any scenario.
See the section [Scenarios][#Scenarios] for details.
+ *message*: replaces the default error message if validation fails.
+ *...validation parameters...*: any number of extra parameters to be used by the specified validator.

**Note**: You may get into trouble when using model's attributes as additional parameters for validators. Take a look at: [https://github.com/yiisoft/yii/issues/3001](https://github.com/yiisoft/yii/issues/3001 "https://github.com/yiisoft/yii/issues/3001")
 

### Choice of validators
[...]
}

public
function validateLogin() { // [...]
 
}
 
```

### Scenarios
[...]
through the `"on" => "scenario"` parameter.


 
## Validation rules reference

For each rule, the list of its specific arguments is given with the eventual default value *(in italics)*.
[...]
7. **tooSmall**, the error message used when the uploaded file is too small.
8. **types**, a list of file name extensions that are allowed to be uploaded. *(null, meaning all extensions)*
9. **wrongType**, the error message used when the uploaded file has an extension name that is not listed among extensions.
 
10. **mimeTypes**, a list of MIME-types of the file that are allowed to be uploaded. *(requires fileinfo PHP extension)*
 
11. **wrongMimeType**, the error message used when the uploaded file has a MIME-type that is not listed among mimeTypes.


### `filter` : [CFilterValidator]
[...]
*Examples:*

- With
standarda custom function ```php array('mycode','filter','filter'=>'strtoupper'), ``` - With custom functionmethod ```php array('eanupc','filter','filter'=>array($this,'keepProductCode')), array('eanupc','filter','filter'=>array(self,'formatProductCode')),
 
... public function keepProductCode($eanupccode){ // return ltrim(substr($eanupc,6,6),'0');s a new value (uses $this) ...
 
}
 
static public function formatProductCode($code){
 
// returns a new value (cannot use $this) ...

}
```
[...]
* [CUniqueValidator]
* [CUnsafeValidator]
* [CUrlValidator]

 
99 0
114 followers
Viewed: 891 781 times
Version: 1.1
Category: How-tos
Written by: krillzip
Last updated by: Rodrigo
Created on: Nov 29, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history