PHP code example of matrozov / yii2-nested-field-validation

1. Go to this page and download the library: Download matrozov/yii2-nested-field-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matrozov / yii2-nested-field-validation example snippets


public function rules(): array
{
    return [
        [['field'], KeyArrayValidator::class, 'rules' => [
            [['nested-field-1'], 'string', 'max' => 255],        
            [['nested-field-2'], 'integer'],        
        ]],
    ];
}

Validator::$globalErrorFormat = Validator::ERROR_FORMAT_DOT;

[['field'], ArrayValidator::class, 'rules' => [...], 'errorFormat' => Validator::ERROR_FORMAT_DOT],

[['field'], KeyArrayValidator::class, 'rules' => [
    [['nested-field'], 'string'],
]],

// MainModel rules
[['field'], KeyModelValidator::class, 'model' => FieldModel::class],

// FieldModel rules
[['nested-field'], 'string'],

[['field'], ArrayValidator::class, 'rules' => [
    [['nested-field-1'], 'string'],
    [['nested-field-2'], 'integer'],
]],

// MainModel::rules
[['field'], ModelValidator::class, 'model' => FieldModel::class],

// FieldModel::rules
[['nested-field-1'], 'string'],
[['nested-field-2'], 'integer'],

[['field'], KeyValidator::class, 'keyRules' => [
    ['string'],
]],

[['field'], KeyValueValidator::class, 'rules' => [
    ['string'],
]],

[['field'], KeyArrayValidator::class, 'rules' => [
    [['nested-field-1'], 'string'],
    [['nested-field-2'], 'integer'],
]],

// MainModel::rules
[['field'], KeyModelValidator::class, 'model' => FieldModel::class], 

// FieldModel::rules
[['nested-field-1'], 'string'],
[['nested-field-2'], 'integer'],