marena/yii2-relation-trait
Composer 安装命令:
composer require marena/yii2-relation-trait
包简介
Yii 2 Models load with relation, & transaction save with relation
关键字:
README 文档
README
Yii 2 Models add functionality for load with relation (loadAll($POST)), & transactional save with relation (saveAll())
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require 'mootensai/yii2-relation-trait:dev-master'
or add
"mootensai/yii2-relation-trait": "*"
to the require section of your composer.json file.
Usage At Model
class MyModel extends ActiveRecord{ use \mootensai\relation\RelationTrait; }
Array Input & Usage At Controller
It takes a normal array of POST. This is the example
// sample at controller //$_POST['ParentClass'] = ['attr1' => 'value1','attr2' => 'value2']; //$_POST['RelatedClass'][0] = ['attr1' => 'value1','attr2' => 'value2']; if($model->loadAll(Yii:$app->request->post()) && $model->saveAll()){ return $this->redirect(['view', 'id' => $model->id, 'created' => $model->created]); }
#Features
Array Output
// I use this to send model & related through JSON / Serialize print_r($model->getAttributesWithRelatedAsPost());
Array
(
[MainClass] => Array
(
[attr1] => value1
[attr2] => value2
)
[RelatedClass] => Array
(
[0] => Array
(
[attr1] => value1
[attr2] => value2
)
)
)
print_r($model->getAttributesWithRelated());
Array
(
[attr1] => value1
[attr2] => value2
[relationName] => Array
(
[0] => Array
(
[attr1] => value1
[attr2] => value2
)
)
)
Use Transaction
So your data will be atomic (see : http://en.wikipedia.org/wiki/ACID)
Use Normal Save
So your behaviors still works
Add Validation At Main Model
$form->errorSummary($model);
will give you
<<Related Class Name>> #<<index + 1>> : <<error message>>
My Related Model #1 : Attribute is required
It Works On Auto Incremental PK Or Not (I Have Tried Use UUID)
See here if you want to use my behavior : https://github.com/mootensai/yii2-uuid-behavior
#To Do Test it on another DB. I only test it on MySQL.
I'm open for any improvement
marena/yii2-relation-trait 适用场景与选型建议
marena/yii2-relation-trait 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.4k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「relation」 「transaction」 「related」 「load」 「yii2」 「save」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marena/yii2-relation-trait 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marena/yii2-relation-trait 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marena/yii2-relation-trait 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A CMS form field for adding has_one relationships using autocomplete
DUKPT implementation in PHP
CakePHP ORM plugin for persisting selected fields of related tables
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Test easier your Eloquent Models in your Laravel Project
Send mails after DB transaction is committed
统计信息
- 总下载量: 3.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-10-25