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

This package is auto-updated.

Last update: 2022-06-22 13:39:24 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.