2017 © Pedro Peláez
 

yii2-extension yii2-eav

EAV para Yii2

image

blacksesion/yii2-eav

EAV para Yii2

  • Monday, April 9, 2018
  • by blacksesion
  • Repository
  • 2 Watchers
  • 0 Stars
  • 26 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 45 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

EAV Atributos Dinamicos para Yii2

EAV(Enity-Attribute-Value) Tomado del trabajo de mirocow, (*1)

Screenshots

Edit attributes

List of attributes

, (*2)

Edit attribute

, (*3)

Edit form

, (*4)

Active field rules

, (*5)

Install

Add github repository

    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/blacksesion/yii2-eav.git"
        }
    ]

and then, (*6)

php composer.phar require --prefer-dist "blacksesion/yii2-eav" "*"

Configure

``` sh php ./yii migrate/up -p=@blacksesion/eav/migrations, (*7)


or ``` sh php ./yii migrate/up -p=@vendor/blacksesion/yii2-eav/src/migrations

Use

Model

Simple

``` php class Product extends \yii\db\ActiveRecord {, (*8)

/**
 *
 *
 */
public function rules()
{
    return [
        [['name'], 'string', 'max' => 255], // Product field
        [['c1'], 'required'], // Attribute field
        [['c1'], 'string', 'max' => 255], // Attribute field
    ];
}

/**
 * create_time, update_time to now()
 * crate_user_id, update_user_id to current login user id
 */
public function behaviors()
{
    return [
        'eav' => [
            'class' => \blacksesion\eav\EavBehavior::className(),
            'valueClass' => \blacksesion\eav\models\EavAttributeValue::className(),
        ]           
    ];
}    

/**
 * @return \yii\db\ActiveQuery
 */
public function getEavAttributes()
{
    return \blacksesion\eav\models\EavAttribute::find()
      ->joinWith('entity')
      ->where([
        'categoryId' => $this->categories[0]->id,
        'entityModel' => $this::className()
    ]);
}

}, (*9)


#### Advanced ``` php class Product extends \yii\db\ActiveRecord { /** * * */ public function rules() { return [ [['name'], 'string', 'max' => 255], // Product field [['c1'], 'required'], // Attribute field [['c1'], 'string', 'max' => 255], // Attribute field ]; } /** * create_time, update_time to now() * crate_user_id, update_user_id to current login user id */ public function behaviors() { return [ 'eav' => [ 'class' => \blacksesion\eav\EavBehavior::className(), 'valueClass' => \blacksesion\eav\models\EavAttributeValue::className(), ] ]; } /** * @return \yii\db\ActiveQuery */ public function getEavAttributes($attributes = []) { return \blacksesion\eav\models\EavAttribute::find() ->joinWith('entity') ->where([ //'categoryId' => $entityId, 'entityModel' => $this::className() ])->andWhere($attributes); } } ### View Insert this code for create widget or load all EAV inputs fields for model ### Form edit fo load selected field ``` php <?=$form->field($model,'test5', ['class' => '\blacksesion\eav\widgets\ActiveField'])->eavInput(); ?>

or for load all fields, (*10)

Simple

``` php getEavAttributes()->all() as $attr){ echo $form->field($model, $attr->name, ['class' => '\blacksesion\eav\widgets\ActiveField'])->eavInput(); } ?>, (*11)


or add sorted ``` php <?php foreach($model->getEavAttributes()->orderBy(['order' => SORT_ASC])->all() as $attr){ echo $form->field($model, $attr->name, ['class' => '\blacksesion\eav\widgets\ActiveField'])->eavInput(); } ?>

Advanced

``` php getEavAttributes(['entityId' => 8, 'typeId' => 3])->all() as $attr){ echo $form->field($model, $attr->name, ['class' => '\blacksesion\eav\widgets\ActiveField'])->eavInput(); } ?>, (*12)


### Partial template ``` php

Encode getEavAttributes()->all() as $attr){ print_r($model[$attr->name]['value']); } ?> , (*13)

< p> String getEavAttributes()->all() as $attr){ echo $model[$attr->name]; } ?>

Add attribute

$attr = new blacksesion\eav\models\EavAttribute();
$attr->attributes = [
        'entityId' => 1, // Category ID
        'name' => 'AttrCategory1',  // service name field
        'label' => 'Attr1',         // label text for form
        'defaultValue' => 'attr1',  // default value
        'entityModel' => SampleModel::className(), // work model
        'required'=>false           // add rule "required field"
    ];
$attr->save();

Administrate GUI

Config module EAV for managment of fields

In main config file:, (*14)

$modules = [
    ...,
    'eav' => [
        'class' => 'blacksesion\eav\Module',
    ],
];

Form

Add / Edit attribute

php <?= \blacksesion\eav\admin\widgets\Fields::widget([ 'model' => $model, 'categoryId' => $model->id, 'entityName' => 'Entidad', 'entityModel' => 'common\models\Product', ])?>, (*15)

The Versions

09/04 2018

dev-master

9999999-dev

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

06/04 2018

1.1.3

1.1.3.0

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

06/04 2018

1.1.2

1.1.2.0

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

28/09 2016

1.1.0

1.1.0.0

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

28/09 2016

1.0.0

1.0.0.0

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

28/09 2016

v1.0.1

1.0.1.0

EAV para Yii2

  Sources   Download

MIT

The Requires

 

by Avatar blacksesion

yii2 fields attribute eav cck

01/08 2016

v0.7.0

0.7.0.0

EAV for Yii2

  Sources   Download

MIT

The Requires

 

by Alien-art

yii2 fields attribute eav cck

01/08 2016

v0.6.2

0.6.2.0

EAV for Yii2

  Sources   Download

MIT

The Requires

 

by Alien-art

yii2 fields attribute eav cck

09/12 2015

v0.6.1

0.6.1.0

EAV for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 fields attribute eav cck

24/10 2015

v0.6.0

0.6.0.0

EAV for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

yii2 fields attribute eav cck

23/09 2015