Skip to content

JC-IT/yii2-json-behavior

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JSON behavior for Yii2

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.

About

JSON behavior for Yii2 that adds magic attributes. Ideal for single table inheritance.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages