jc-it / yii2-json-behavior
JSON behavior for Yii2 that adds magic attributes. Ideal for single table inheritance.
v1.0.0
2019-07-10 12:20 UTC
Requires
- php: >=7.1.0
- yiisoft/yii2: ~2.0.19
This package is auto-updated.
Last update: 2024-10-22 18:41:00 UTC
README
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.
Configuration
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>' ] ] ], ] ); }
Credits
License
The MIT License (MIT). Please see LICENSE for more information.