dev-master
9999999-devAttaches behavior for a Postgresql jsonb column
Apache-2.0
The Requires
by Jonathan Berall
extension json yii2 behavior attributes models arrays jsonb postgresql
Attaches behavior for a Postgresql jsonb column
Attaches behavior for a Postgresql jsonb column, (*1)
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)
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); }
Attaches behavior for a Postgresql jsonb column
Apache-2.0
extension json yii2 behavior attributes models arrays jsonb postgresql