承接 yiisoft-custom/yii2-model-attribute-convert 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

yiisoft-custom/yii2-model-attribute-convert

Composer 安装命令:

composer require yiisoft-custom/yii2-model-attribute-convert

包简介

Base on Yii2 BaseActiveRecord. Converts column from db format to model format while SELECT,oppositely way while INSERT or UPDATE

README 文档

README

Attribute value converted between db format and Yii2 model format

Require yiisoft/yii2

Installation

composer require yiisoft-custom/yii2-model-attribute-convert

Notice & Important

Case the attribute set an converter in cast,it would be converted to model format while trigger EVENT_AFTER_FIND, and the model value strictly is already changed (e.g: db value format is json [1,2,3],with 'Array' converter , model format would bearray(1,2,3)). the result of these method calls would be effected :

isAttributeChanged(),
getOldAttribute(),
getOldAttributes(),
getDirtyAttributes()

But don't worry,we gotta the suitable calls instead while any attribute of model casted with a converter,list of mapper:

isAttributeChangedWithConverter()   -> isAttributeChanged()
getOldAttributeWithConverter()      -> getOldAttribute()
getOldAttributesWithConverter()     -> getOldAttributes()
getDirtyAttributesWithConverter()   -> getDirtyAttributes()

Usage

<?php
class Test extends ActiveRecord
{


    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['attribute_convert'] = [
            'class' => AttributeConverted::class,
            'cast' => [
                'order_no' => 'Array',
            ]
        ];

        return $behaviors;
    }
}

?>

Just used like other behavior class. Property $cast is key-value(eg: 'order_no' => 'Array'). Key is the attribute needs to be converted,and value is the converter,class name or string maps a class name would be fine

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固