Skip to content

matrozov/yii2-each-key-value-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yii2-each-key-value-validator

This extension provides the simple key-value validation for Yii framework 2.0.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads License

Installation

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.

Usage

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.

Releases

No releases published

Packages

No packages published

Languages