PHPackages                             mazurva/yii2-eav - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mazurva/yii2-eav

ActiveLibrary[Database &amp; ORM](/categories/database)

mazurva/yii2-eav
================

EAV for Yii2

v0.5.0(10y ago)21092MITPHPPHP &gt;=5.4.0

Since Sep 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/mazurva/yii2-eav)[ Packagist](https://packagist.org/packages/mazurva/yii2-eav)[ RSS](/packages/mazurva-yii2-eav/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (9)Used By (0)

EAV Dynamic Attributes for Yii2
===============================

[](#eav-dynamic-attributes-for-yii2)

[![Build Status](https://camo.githubusercontent.com/67abcf562e8be9c65d26a13b0ed8fdb1a7974185d54aebef62c77ebf3598bc59/68747470733a2f2f7472617669732d63692e6f72672f6d617a757276612f796969322d6561762e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mazurva/yii2-eav)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist mazurva/yii2-eav "dev-master"
```

or add

```
"mazurva/yii2-eav": "dev-master"

```

to the require section of your `composer.json` file.

```
php yii migrate/up --migrationPath=@vendor/mazurva/yii2-eav/src/migrations
```

Usage
-----

[](#usage)

Attach to your model

```
  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']);
  }
```

Sample use in view:

```
