A validator that validates some content if it passes at least one of other specified validators.
A validator that validates some content if it passes at least one of other specified validators.
The installation of this library is made via composer.
Download composer.phar
from their website.
Then add to your composer.json :
"require": {
...
"yii1-extended/yii1-or-validator": "^1",
...
}
Then run php composer.phar update
to install this library.
The autoloading of all classes of this library is made through composer's autoloader.
In the model validation :
public function rules()
{
return array(
...
array('<attribute names>', 'COrValidator', 'rules' => array(
...
array('CNumberValidator', 'allowEmpty' => true),
array('CStringValidator', 'min' => 0, 'max' => 9),
...
),
...
);
}
This validator validates a specific attribute, considering it validated if at least one of the inner validator validates the attribute.
When the rules for the inner validators are created, their 0th attribute (a.k.a. the list of attributes for which this validator will validate against) is not needed anymore because all the inner validators will check all the values of the array to validate. Thus, their new 0th attribute should be their classname, or built-in validator name.
MIT (See license file).