PHP code example of sovngare / yii2-array-validator

1. Go to this page and download the library: Download sovngare/yii2-array-validator 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/ */

    

sovngare / yii2-array-validator example snippets


public function rules()
{
    return [
        ['fields', '

public function rules()
{
    return [
        ['fields', ArrayValidator::class, 'key' => 'status.code', 'rules' => [
            ['integer', 'min' => 100, 'max' => 500]
        ]]
    ];
}

public function rules()
{
    return [
        ['fields', ArrayValidator::class, 'key' => 'status.code', 'rules' => [
            ['integer', 'min' => 100, 'max' => 500]
        ], 'label' => 'status_code']
    ];
}

class TestModel extends Model
{
    public $phone;
    public $fields;

    public function rules()
    {
        return [
            [['phone', 'fields'], '         ], 'label' => 'name'],
            ['fields', ArrayValidator::class, 'key' => 'avatar', 'rules' => [
                ['

public function actionIndex()
{
    $model = new TestModel();
    $model->attributes = Yii::$app->request->getBodyParams();

    if (is_array($model->fields)) {
        $model->fields['avatar'] = UploadedFile::getInstanceByName('fields[avatar]');
    }

    if (!$model->validate()) {
        return $model->errors;
    }

    return $model->attributes;
}