PHP code example of fgh151 / yii2-postgresql-array-field

1. Go to this page and download the library: Download fgh151/yii2-postgresql-array-field library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fgh151 / yii2-postgresql-array-field example snippets


$this->createTable('UserReward', [
    'jsonField' => fgh151\PostgresqlJsonb\db\Schema::TYPE_JSONB
]);

use yii\db\ActiveRecord;
use \fgh151\PostgresqlJsonb\PostgresqlJsonbFieldBehavior;

/**
 * @property array $modelField
 */
class Model extends ActiveRecord{
	public function behaviors() {
		return [
			[
				'class' => PostgresqlJsonbFieldBehavior::className(),
				'arrayFieldName' => 'modelField', // model's field to attach behavior
				'onEmptySaveNull' => true // if set to false, empty array will be saved as empty PostreSQL array '{}' (default: true)
			]
		];
	}
}

$model->jsonField->property = 'value';
$model->jsonField->otherProperty->otherPropertyValue = 'another value';