2017 © Pedro Peláez
 

yii2-extension yii2-json-data-behavior

Enables you to easily encode and decode json in your activerecords.

image

locustv2/yii2-json-data-behavior

Enables you to easily encode and decode json in your activerecords.

  • Friday, March 31, 2017
  • by Locustv2
  • Repository
  • 1 Watchers
  • 1 Stars
  • 89 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

JsonData behavior for Yii2 ActiveRecords

Enables you to easily encode and decode json in your activerecords. It automatically encodes before validating and saving to database and decodes after., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Installation

The preferred way to install the library is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist locustv2/yii2-json-data-behavior

or add, (*5)

{
    "require": {
        "locustv2/yii2-json-data-behavior": "~1.0.0"
    }
}

to your composer.json file., (*6)

Usage

public function behaviors()
{
    return [
        'class' => \locustv2\behaviors\JsonDataBehavior::className(),
        'dataAttribute' => 'hotel_data',
    ];
}

After configuring your activerecord as above, you can use as follows:, (*7)

$model = Hotel::find()->one();

var_dump($model->getData('rooms')); // assume it returns a list of rooms
var_dump($model->getData('rooms.0.price')); // to get rooms data

$model->setData('ratings', [
    '5star' => ['count' => 100],
    '4star' => ['count' => 200],
    '3star' => ['count' => 20],
    '2star' => ['count' => 75],
    '1star' => ['count' => 50],
]);

var_dump($model->getData('ratings.3star.count')); // returns 20

To do

  • Add unit tests

Contributing

Feel free to send pull requests., (*8)

License

For license information check the LICENSE-file., (*9)

The Versions

31/03 2017

dev-master

9999999-dev https://github.com/locustv2/

Enables you to easily encode and decode json in your activerecords.

  Sources   Download

BSD-3-Clause

The Requires

 

by Yuv Joodhisty

json yii2 behavior activerecord data encode decode

31/03 2017

1.0.0

1.0.0.0 https://github.com/locustv2/

Enables you to easily encode and decode json in your activerecords.

  Sources   Download

BSD-3-Clause

The Requires

 

by Yuv Joodhisty

json yii2 behavior activerecord data encode decode