dev-master
9999999-devEAV behavior for ActiveRecord
BSD-3-Clause
The Requires
by Aleksandr Reshevskiy
EAV behavior for ActiveRecord
EAV-behavior, (*1)
============, (*2)
EAV behavior for ActiveRecord, (*3)
Installation, (*4)
The preferred way to install this extension is through composer., (*5)
Either run, (*6)
php composer.phar require --prefer-dist reshik84/yii2-eav-behavior "*"
or add, (*7)
"reshik84/yii2-eav-behavior": "*"
to the require section of your composer.json
file., (*8)
$ php yii migrate/up --migrationPath=@vendor/reshik84/yii2-eav-behavior/migrations
Usage, (*9)
Once the extension is installed, add to your model :, (*10)
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:, (*11)
$model = new Model(); $attr = $model->attr1; // get value $model->attr1 = 'some value'; // set value $model->save();
EAV behavior for ActiveRecord
BSD-3-Clause