reshik84 / yii2-eav-behavior
EAV behavior for ActiveRecord
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ^2.0
This package is not auto-updated.
Last update: 2025-08-17 07:33:48 UTC
README
EAV-behavior
============
EAV behavior for ActiveRecord
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist reshik84/yii2-eav-behavior "*"
or add
"reshik84/yii2-eav-behavior": "*"
to the require section of your composer.json
file.
$ php yii migrate/up --migrationPath=@vendor/reshik84/yii2-eav-behavior/migrations
Usage
Once the extension is installed, add to your model :
public function behaviors() { return [ 'eav' => [ 'class' => resh\eav\behaviors\EavBehavior::className(), 'model_id' => 'id' // primary key ] ]; } // list of EAV attributes public function additionalAttributes(){ return ['attr1', 'attr2', 'attr3', ... ]; } public function rules() { return [ [['attr1', 'attr2', 'attr3'], 'safe'] ]; } public function attributeLabels() { return [ 'attr1' => 'Attribute 1', 'attr2' => 'Attribute 2', 'attr3' => 'Attribute 3', ]; }
Call EAV attributes:
$model = new Model(); $attr = $model->attr1; // get value $model->attr1 = 'some value'; // set value $model->save();