locustv2/yii2-json-data-behavior
Composer 安装命令:
composer require locustv2/yii2-json-data-behavior
包简介
Enables you to easily encode and decode json in your activerecords.
README 文档
README
Enables you to easily encode and decode json in your activerecords. It automatically encodes before validating and saving to database and decodes after.
Installation
The preferred way to install the library is through composer.
Either run
php composer.phar require --prefer-dist locustv2/yii2-json-data-behavior
or add
{
"require": {
"locustv2/yii2-json-data-behavior": "~1.0.0"
}
}
to your composer.json file.
Usage
public function behaviors() { return [ 'class' => \locustv2\behaviors\JsonDataBehavior::className(), 'dataAttribute' => 'hotel_data', ]; }
After configuring your activerecord as above, you can use as follows:
$model = Hotel::find()->one(); var_dump($model->getData('rooms')); // assume it returns a list of rooms var_dump($model->getData('rooms.0.price')); // to get rooms data $model->setData('ratings', [ '5star' => ['count' => 100], '4star' => ['count' => 200], '3star' => ['count' => 20], '2star' => ['count' => 75], '1star' => ['count' => 50], ]); var_dump($model->getData('ratings.3star.count')); // returns 20
To do
- Add unit tests
Contributing
Feel free to send pull requests.
License
For license information check the LICENSE-file.
统计信息
- 总下载量: 241
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-03-31