petrgrishin / yii2-array-field
Yii2 array field behavior
2.0.0
2014-06-26 07:40 UTC
Requires
- php: >=5.4.0
- petrgrishin/array-access: ~2.0
- yiisoft/yii2: *
Requires (Dev)
- league/phpunit-coverage-listener: ~1.0
- yiisoft/yii2: 2.0.0-beta
- yiisoft/yii2-composer: *
This package is not auto-updated.
Last update: 2024-11-09 16:53:16 UTC
README
Yii2 array field behavior (usage https://github.com/petrgrishin/array-access)
Installation
Add a dependency to your project's composer.json:
{ "require": { "petrgrishin/yii2-array-field": "~2.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();