yii2-array-field Yii2 array field behavior, for simple storage array in you model

  1. Installation
  2. Usage examples

https://github.com/petrgrishin/yii2-array-field

Yii2 array field behavior (usage https://github.com/petrgrishin/array-access and https://github.com/petrgrishin/array-map)

Installation

Add a dependency to your project's composer.json: ~~~ {

"require": {
    "petrgrishin/yii2-array-field": "~1.0"
}

} ~~~

Usage examples

Attach behavior to you model

Model have text attribute data for storage array

namespace app\models;

use yii\db\ActiveRecord;
use \PetrGrishin\ArrayField\ArrayAccessFieldBehavior;

class Model extends ActiveRecord{
    public function behaviors() {
        return [
            'arrayField' => [
                'class' => ArrayAccessFieldBehavior::className(),
                'fieldNameStorage' => 'data',
            ]
        ];
    }

}
Usage behavior
$model = Model::find(1)->one();
$model->arrayField->setValue('a.b', true);
$value = $model->arrayField->getValue('a.b');
$array = $model->arrayField->getArray();
Save only array field
$model = Model::find(1)->one();
$model->arrayField->setValue('a.b', true);
$model->arrayField->save();
1 0
2 followers
287 downloads
Yii Version: 2.0
License: MIT
Category: Database
Developed by: Petr.Grishin
Created on: May 6, 2014
Last updated: 9 years ago

Downloads

show all

Related Extensions