macklus/yii2-metadatabehavior Simple behavior to use json-like fields on bbdd

extensionbehavior

yii2-metadatabehavior

MetaDataBehavior allow to use one TEXT field on a database as a json data To use MetaDataBehavior, simply add this behavior into your behaviors model function

use macklus\MetaDataBehavior\MetaDataBehavior;

public function behaviors()
{
    return [
        [
            'class' => MetaDataBehavior::className(),
            'attribute' => 'metadata',
        ],
    ];
}

Your model table should have a TEXT field named as attribute property

Then, in your controller, you can user getMetaData(keyword,default) and setMetaData(keyword, value)


$model = MyModel::find()->where(['id' => 1])->one();
$model->setMetaData('keyword1','value1');
$model->setMetaData('otherkeyword','anothervalue');

// Other stuff
echo $model->getMetaData('keyword1');

@author José Pedro Andrés <macklus@debianitas.net>
@since 2.0Yii2 MetaData Behavior

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.0.1 is the latest of 2 releases



Apache-2.0 license
Stats
1 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
39 total downloads