Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Yii array field behavior, for simple storage array in you model
https://github.com/petrgrishin/yii-array-field

Last synced: 8 days ago
JSON representation

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

Awesome Lists containing this project

README

        

yii-array-field
===============
[![Travis CI](https://travis-ci.org/petrgrishin/yii-array-field.png "Travis CI")](https://travis-ci.org/petrgrishin/yii-array-field)
[![Coverage Status](https://coveralls.io/repos/petrgrishin/yii-array-field/badge.png?branch=master)](https://coveralls.io/r/petrgrishin/yii-array-field?branch=master)

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

Installation
------------
Add a dependency to your project's composer.json:
```json
{
"require": {
"petrgrishin/yii-array-field": "~2.0"
}
}
```

Usage examples
--------------
#### Attach behavior to you model
Model have text attribute `data` for storage array

```php
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
```php
$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
```php
$model = Model::find(1)->one();
$model->arrayField->setValue('a.b', true);
$model->arrayField->save();
```