Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 3375

[extension] magp/yii2-json-schema-validator

$
0
0

Yii 2 JSON Schema Validator

  1. Installation
  2. Usage

A Yii 2 extension that provides a validation class that wraps JSON Schema for PHP.

Installation

$ composer require magp/yii2-json-schema-validator

Usage

Model class example:

<?php

namespace app\models;

use magp\yii2jsv\JsonSchemaValidator;
use Yii;
use yii\base\Model;

class YourCustomModel extends Model
{
    public $json;

    public function rules()
    {
        return [
            [
                'json',
                JsonSchemaValidator::className(),
                'schema' => 'file://' . Yii::getAlias('@app/path/to/schema.json'),
                /* or URL
                'schema' => 'https://example.com/path/to/schema.json',
                */
            ],
        ];
    }
}

See json-schema for details how to describe JSON schema.


Viewing all articles
Browse latest Browse all 3375

Trending Articles