emidia/yii2-jsonify 问题修复 & 功能扩展

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

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

emidia/yii2-jsonify

最新稳定版本:v1.0

Composer 安装命令:

composer require emidia/yii2-jsonify

包简介

Behavior that convert array to JSON before save data in model

README 文档

README

Behavior that convert array to JSON before save data in model

Install

Install via composer

composer require emidia/yii2-jsonify

Or you may add dependency manually in composer.json:

 "emidia/yii2-jsonify": "*"

How to use

To use JsonifyBehavior, insert the following code to your ActiveRecord class:

use emidia\yii2\JsonifyBehavior;
public function behaviors()
{
    return [
        JsonifyBehavior::className(),
    ];
}

By default JsonifyBehavior fill json_data attribute from array into a json encoded string

If your attribute names are different, you may configure the [[attribute]] properties like the following:

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

So, if set an array in model's attribute, this behavior will convert all data to JSON

$model->setAttributes([
  'data' => [
    'id'=> 12,
    'title' => 'test'
  ]
]);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-25