This extension provides the simple key-value validation for Yii framework 2.0.
For license information check the LICENSE-file.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist matrozov/yii2-each-key-value-validator
or add
"matrozov/yii2-each-key-value-validator": "dev-master"
to the require section of your composer.json.
class MyClass extends \yii\base\Model
{
public $data;
public function rules()
{
return [
[['data'], EachKeyValueValidator::class, 'rules' => [
[['key', 'value'], 'string'], // Validate, what key and value must be string.
]],
];
}
}
$model = new MyModel();
$model->data = [
'myKey' => 2,
];
$model->validate();
print_r($model->errors);
You got error: Data:value must be a string
!
You can assign variable validation for key
and value
pseudo-field.