承接 emidia/yii2-jsonify 相关项目开发

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

邮箱: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
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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