Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/petrgrishin/yii-array-field
- Owner: petrgrishin
- Created: 2014-05-19T19:46:04.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-26T07:52:31.000Z (over 10 years ago)
- Last Synced: 2024-11-08T16:17:00.615Z (2 months ago)
- Language: PHP
- Size: 199 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
```