承接 amnah/yii2-classes 相关项目开发

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

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

amnah/yii2-classes

Composer 安装命令:

composer require amnah/yii2-classes

包简介

Yii2 classes

README 文档

README

A various collection of classes. Install using composer "amnah/yii2-classes": "dev-master".

Table of Contents

  • [Behaviors/SoftDelete] (#softdelete)
  • [Widgets/ExtListView] (#extlistview)
  • [Test/DbToDbFixtureManager] (#dbtodbfixturemanager)

SoftDelete

This class adds soft-delete functionality to ActiveRecord models.

Before you use this, please see this response to decide if you really need this functionality.

Usage

  • Add column `delete_time` (int or timestamp DEFAULT NULL) to your database table
  • Add behavior to your model
public function behaviors() {
    return [
        'softDelete' => [
            'class' => 'amnah\yii2\behaviors\SoftDelete',
            // these are the default values, which you can omit
            'attribute' => 'delete_time',
            'value' => null, // this is the same format as in TimestampBehavior
            'safeMode' => true, // this processes '$model->delete()' calls as soft-deletes
        ],
    ];
}
  • Call functions
// soft-delete model
$model->remove();

// restore model
$model->restore();

// delete model from db
$model->forceDelete();

// soft-delete model if $safeMode = true
// delete model from db if $safeMode = false
$model->delete();
  • (Optional) Update model by adding default condition/scope to select only non-deleted records
class Customer extends ActiveRecord
{
    public static function find()
    {
        return parent::find()->where(['delete_time' => null]);
    }
}

ExtListView

The ExtListView class extends the default yii\widgets\ListView class by adding in views and closures.

Usage

Using views:

// @app/views/list/index.php
<?php echo ExtListView::widget([
    // ...
    "layoutView" => "_list",
    "layoutViewParams" => [
        // variables to pass into layoutView
    ],
    "emptyView" => "_listEmpty",
    "emptyViewParams" => [
        // variables to pass into emptyView
    ],
    // ...
]); ?>
// @app/views/list/_list.php
<div>{summary}</div>
<div>{pager}</div>

<div id="listitems" class="row">
    {items}
</div>

Using closures:

<?php echo ExtListView::widget([
    // ...
    "layoutView" => function() {
        return '
            <div>{summary}</div>
            <div>{pager}</div>
            <div id="listitems" class="row">
                {items}
            </div>
        ';
    },
    'emptyView' => function() {
        return '<div>nothing found</div>';
    },
    // ...
]); ?>

DbToDbFixtureManager

The DbToDbFixtureManager class loads fixtures in from another database instead of from php arrays.

This is useful if you constantly change your db schema. For example, you can simply copy your developmentDb via phpMyAdmin and use that as your fixtureDb - no need to go through several php files and manually update data. From there, it's also easier to manipulate the data when you have sql commands at your disposal.

Additionally, this is useful if you have lots of fixture data. It is significantly faster to copy tables in sql than it is to load arrays in php and manually insert each individual record (which is the current implementation of DbFixtureManager).

Note: Currently, the fixtureDb must be on the same db connection as the testDb (same server, user, and password). This is because loads the data by using insert into `fixtureDb`.`table select * from testDb.table.

Usage

// @app/tests/unit/_config.php
'components' => [
    'fixture' => [
        'class' => 'amnah\yii2\test\DbToDbFixtureManager',
        'fixtureDb' => 'databasename_test',
    ],
]
// @app/tests/unit/models/UserTest.php
protected function setUp() {
    parent::setUp();

    // load fixtures using same exact call
    $this->loadFixtures(['tbl_user']);
}

amnah/yii2-classes 适用场景与选型建议

amnah/yii2-classes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.58k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Fixture」 「softdelete」 「yii」 「yii2」 「soft-delete」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 amnah/yii2-classes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amnah/yii2-classes 我们能提供哪些服务?
定制开发 / 二次开发

基于 amnah/yii2-classes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-02