mar/yii2-simple-eav
Composer 安装命令:
composer require mar/yii2-simple-eav
包简介
simple way to add to your application dynamic attributes to every model you wish
关键字:
README 文档
README
Attention!: extension is not finished, it needs some update and fixes ( for example, remove deleted eav fields from eav tables, check performance and so on )
Simple EAV
simple way to add to your application dynamic attributes to every model you wish
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mar/yii2-simple-eav "*"
or add
"mar/yii2-simple-eav": "*"
to the require section of your composer.json file.
execute migrations from migration folder of extension
Usage
Once the extension is installed, simply use it in your code by :
Add behavior,alias and validation rules to your model like this: ( you can use any alias it will be used to identify your $model::className in db if you will change alias, old attribute values will disappear =)) )
public function behaviors() {
return [ [ 'class' => \mar\eav\behaviors\EavBehavior::className(), 'modelAlias' => 'product', 'eavAttributesList' => [ 'eavProperty1' => [ 'rule' => [['eavProperty1'], 'string', 'max' => 255], 'type' => EavBehavior::ATTRIBUTE_TYPE_TEXT, ], 'eavProperty2' => [ 'rule' => [['eavProperty2'], 'integer'], 'type' => EavBehavior::ATTRIBUTE_TYPE_ARRAY, // mode MODE_SET_EMPTY_IF_NO_VALUE_IN_REQUEST - clear attribute value if no value like Classname[attributeName] in request, usefull for forms handling 'modes' => [ EavBehavior::MODE_SET_EMPTY_IF_NO_VALUE_IN_REQUEST ] ], ..... ] ] ];}
If you wish you can add labels for eav properties to attributeLabels() method of your model
3.That's all, you cat access your new property like $model->eavProperty1, also you can use it in form like this :
<?= $form->field($model, 'eavProperty1')->textInput(['maxlength' => true]) ?>
PS: 1)attributes and values will be removed if you delete them from behavior config
possible future updates:
1. search by eav fields
2. relations by eav fields
3. using category_id to bind eav attributes to class by category
统计信息
- 总下载量: 330
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-06