PHP code example of mazurva / yii2-eav

1. Go to this page and download the library: Download mazurva/yii2-eav library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mazurva / yii2-eav example snippets


  use EavTrait; // need for full support label of fields

  public function behaviors()
  {
      return [
          'eav' => [
              'class' => mazurva\eav\EavBehavior::className(),
              'valueClass' => mazurva\eav\models\EavAttributeValue::className(), // this model for table object_attribute_value
          ]
      ];
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getEavAttributes()
  {
      return $this->hasMany(mazurva\eav\models\EavAttribute::className(), ['categoryId' => 'id']);
  }

<?=$form->field($model,'eav2'); 

foreach($model->eavAttributes as $attr){
    echo $form->field($model, $attr->name)->textInput();
}

$attr = new mazurva\eav\models\EavAttribute();
$attr->attributes = [
        'categoryId' => 1, // Category ID
        'name' => 'AttrCategory1',  // service name field
        'label' => 'Attr1',         // label text for form
        'defaultValue' => 'attr1',  // default value
        'entityModel' => SampleModel::className(), // work model
        '
 sh
php yii migrate/up --migrationPath=@vendor/mazurva/yii2-eav/src/migrations