定制 mar/yii2-simple-eav 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 :

  1. 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
                     ]
                 ],
                 .....
             ]
         ]
    
     ];
    

    }

  2. 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固