2017 © Pedro Peláez
 

yii2-extension yii2-json-behavior

Attaches behavior for a Postgresql jsonb column

image

jberall/yii2-json-behavior

Attaches behavior for a Postgresql jsonb column

  • Tuesday, May 16, 2017
  • by jberall
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Json Behavior

Attaches behavior for a Postgresql jsonb column, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist jberall/yii2-json-behavior "*"

or add, (*4)

"jberall/yii2-json-behavior": "*"

to the require section of your composer.json file., (*5)

Usage

Once the extension is installed, simply use it in your code by: You need to identify the json_attribute as your column in the database. Will check to see if model and attribute exist., (*6)

use jberall\jsonbehavior;, (*7)

//declare the variables.
//attributes.
public $some_attribute,$another_attribute;
//objects
public $dimension;
//arrayObjects.
public $emails, $phone_numbers;



public function behaviors() {

    $behaviors = [
        'attributeJsonBehavior' =>[
            'class' => JsonBehavior::className(),
            'attributes' => ['some_attribute'=>null, 'another_attribute'=>null],
            'json_attribute'=> 'data_json',
        ],
        'objectJsonBehavior' => [
            'class' => JsonBehavior::className(),
            'arrayObjects' => [
                'dimension'=>'\full\path\Dimension',

             ],
            'json_attribute'=> 'data_json',                
        ],
        'arrayObjectsJsonBehavior' => [
            'class' => JsonBehavior::className(),
            'arrayObjects' => [
                'emails'=>\full\path\'Email',
                'phone_numbers'=>'\full\path\PhoneNumber',
             ],
            'json_attribute'=> 'data_json',                
        ],

        //OR Combine into one.
        'namedBehavior' => [
            'class' => JsonBehavior::className(),
            'attributes' => ['some_attribute'=>null, 'another_attribute'=>null],
            'arrayObjects' => [
                'dimension'=>'\full\path\Dimension',

             ],
            'arrayObjects' => [
                'emails'=>\full\path\'Email',
                'phone_numbers'=>'\full\path\PhoneNumber',
             ],              
            'json_attribute'=> 'data_json',         
        ],
    ];
    return ArrayHelper::merge(parent::behaviors(),$behaviors);

}

The Versions

16/05 2017

dev-master

9999999-dev

Attaches behavior for a Postgresql jsonb column

  Sources   Download

Apache-2.0

The Requires

 

by Jonathan Berall

extension json yii2 behavior attributes models arrays jsonb postgresql