2017 © Pedro Peláez
 

library yii2-jsonify

Behavior that convert array to JSON before save data in model

image

emidia/yii2-jsonify

Behavior that convert array to JSON before save data in model

  • Thursday, October 1, 2015
  • by rzani
  • Repository
  • 5 Watchers
  • 0 Stars
  • 171 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

Yii2 JSONify

Behavior that convert array to JSON before save data in model, (*1)

Install

Install via composer, (*2)

composer require emidia/yii2-jsonify

Or you may add dependency manually in composer.json:, (*3)

 "emidia/yii2-jsonify": "*"

How to use

To use JsonifyBehavior, insert the following code to your ActiveRecord class:, (*4)

use emidia\yii2\JsonifyBehavior;
public function behaviors()
{
    return [
        JsonifyBehavior::className(),
    ];
}

By default JsonifyBehavior fill json_data attribute from array into a json encoded string, (*5)

If your attribute names are different, you may configure the [[attribute]] properties like the following:, (*6)

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

So, if set an array in model's attribute, this behavior will convert all data to JSON, (*7)

$model->setAttributes([
  'data' => [
    'id'=> 12,
    'title' => 'test'
  ]
]);

The Versions

01/10 2015

dev-master

9999999-dev

Behavior that convert array to JSON before save data in model

  Sources   Download

MIT

by Rodrigo Zani

25/09 2015

v1.0

1.0.0.0

Behavior that convert array to JSON before save data in model

  Sources   Download

MIT

by Rodrigo Zani