mkiselev/yii2-serialize-attribute-behavior 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mkiselev/yii2-serialize-attribute-behavior

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mkiselev/yii2-serialize-attribute-behavior

包简介

Yii2 serialize attribute behavior

README 文档

README

This Yii 2.0 ActiveRecord behavior allows you to store serialized values in attributes.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist mkiselev/yii2-serialize-attribute-behavior "*"

or add

"mkiselev/yii2-serialize-attribute-behavior": "*"

to the require section of your composer.json file.

Usage

Behavior adds property named "$attribute . $unserializedAttributeSuffix" to your ActiveRecord class.

You can get unserialized property value like $model->propertyArray.

You can set unserialized property value like $model->propertyArray = [].

Basic

If you want to just serialize and unserialize attribute use a config like the following:

public function behaviors()
{
    return [
        ...
        [
            'class' => SerializeAttributeBehavior::className(),
            'attribute' => 'data',
            'unserializedAttributeSuffix' => 'Array',
        ],
        ...
    ];
}

Advanced

If you need more flexible logic, you may configure behavior like this:

public function behaviors()
{
    return [
        ...
        [
            'class' => SerializeAttributeBehavior::className(),
            'attribute' => 'data',
            'unserializedAttributeSuffix' => 'Model',
            // MyModel must extend mkiselev\serialized\Model
            'setAttributesToModel' => MyModel::className(),
            'setAttributesToModelSafeOnly' => true,
            // serializerClass must implements mkiselev\serialized\interfaces\SerializerInterface
            'serializerClass' => MySerializer::className(),
        ],
        ...
    ];
}

In the example above MyModel must contain attributes, rules, and more in order to support ActiveField attributes unserialization.

For example:

<?= $form->field($model, 'activeRecordModelAttribute')->textInput(); ?>
<?= $form->field($model->dataModel, 'MyModelAttribute')->textInput(); ?>

Use cases

  • This behavior was developed primarily for use with JSON in PostgreSQL and MariaDB columns.
  • You may use it to store any serialized data as text.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固