This extension provides a package that implements magic getters and setters based on a list of configured attributes. Ideal for single table inheritance.
$ composer require jc-it/yii2-json-behavior
or add
"jc-it/yii2-json-behavior": "^<latest version>"
to the require
section of your composer.json
file.
In a model:
/**
* @return array
*/
public function behaviors(): array
{
return ArrayHelper::merge(
parent::behaviors(),
[
JsonConfigurationBehavior::class => [
'class' => JsonConfigurationBehavior::class,
'jsonAttributes' => [
'<jsonAttribute>' => [
'<attribute>' => '<defaultValue>'
'<attribute2>' => '<defaultValue2>'
],
'<jsonAttribute2>' => [
'<attribute3>' => '<defaultValue3>'
'<attribute4>' => '<defaultValue4>'
]
]
],
]
);
}
The MIT License (MIT). Please see LICENSE for more information.