Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 1.4 KB

README.md

File metadata and controls

29 lines (22 loc) · 1.4 KB

Scrutinizer Code Quality Code Coverage Build Status Total Downloads Latest Stable Version

Yii2 JsonBehavior

Work with JSON fields in Yii2

This behavior adds advanced support for working with JSON data in Yii AR models.

Use JSON fields like normal fields

Consider a model having a data attribute that is stored as JSON.

public function behaviors() {
    return [
        ['class' => JsonBehavior::class, 'jsonAttributes' => ['data']]
    ];
}

// Examples:
$model = new Model();
$model->a = "test"; // If attribute 'a' does not exist this is stored inside the data.

$model->a['b'] = 'c']; // Nested arrays are supported.

$model->data = ['x' => 'y']; // Assigning directly is supported.