Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petrgrishin/yii2-array-field
Yii2 array field behavior, for simple storage array in you model
https://github.com/petrgrishin/yii2-array-field
array php storage-array yii yii2
Last synced: about 2 months ago
JSON representation
Yii2 array field behavior, for simple storage array in you model
- Host: GitHub
- URL: https://github.com/petrgrishin/yii2-array-field
- Owner: petrgrishin
- Created: 2014-05-04T15:38:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-26T07:52:01.000Z (over 10 years ago)
- Last Synced: 2024-07-17T09:51:20.734Z (5 months ago)
- Topics: array, php, storage-array, yii, yii2
- Language: PHP
- Homepage:
- Size: 227 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
yii2-array-field
================
[![Travis CI](https://travis-ci.org/petrgrishin/yii2-array-field.png "Travis CI")](https://travis-ci.org/petrgrishin/yii2-array-field)
[![Coverage Status](https://coveralls.io/repos/petrgrishin/yii2-array-field/badge.png?branch=master)](https://coveralls.io/r/petrgrishin/yii2-array-field?branch=master)Yii2 array field behavior (usage https://github.com/petrgrishin/array-access)
Installation
------------
Add a dependency to your project's composer.json:
```json
{
"require": {
"petrgrishin/yii2-array-field": "~2.0"
}
}
```Usage examples
--------------
#### Attach behavior to you model
Model have text attribute `data` for storage array```php
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
```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();
```