petrgrishin/yii-array-field

Yii array field behavior

Installs: 90

Dependents: 1

Stars: 1

Watches: 1

Forks: 1

Language: PHP

2.0.0 2014-06-26 07:35 UTC

README

Travis CI Coverage Status

Yii array field behavior, for simple storage array in you model

Installation

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

{
    "require": {
        "petrgrishin/yii-array-field": "~2.0"
    }
}

Usage examples

Attach behavior to you model

Model have text attribute data for storage array

namespace app\models;

use \CActiveRecord as ActiveRecord;
use \PetrGrishin\ArrayField\ArrayAccessFieldBehavior;

class Model extends ActiveRecord {
    public function behaviors() {
        return array(
            'arrayField' => array(
                '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();