maika-kanaka/ci3-eloquent 问题修复 & 功能扩展

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

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

maika-kanaka/ci3-eloquent

Composer 安装命令:

composer require maika-kanaka/ci3-eloquent

包简介

A simple eloquent for easier your life

README 文档

README

A query builder++ on codeigniter3 for easier your life.

HOW TO USE

  • Step 1: Run this command in your codeigniter project
composer require maika-kanaka/ci3-eloquent
  • Step 2: Extend your model & define your table name in property
<?php defined('BASEPATH') OR exit('No direct script access allowed');

use Eloquent\Eloquent;

class My_model_name extends Eloquent
{

  public $table = 'my_table_name';

  public function __construct()
  {
    parent::__construct();
  }

}

METHOD

table(alias)
Param Type Required Description
alias String No Given alias to your table, it's usefull when you're using join statement

Example 1: a simple query to get data

$data = $this->My_model_name->table()->get()->result();

Example 2: a simple query with join statement to get data

$data = $this->My_model_name->table('t1')
              ->join('my_other_table_name AS t2', 't1.id_fk = t2.id_fk')
              ->get()->result();
find(where)
Param Type Required Description
where Array or Integer or String No Get the first row with where clause

~ Example 1: get the first row with primary key

$data = $this->My_model_name->find('INV-202010-0001');

~ Example 1: get the first row with other column

$data = $this->My_model_name->find(['status => 'active', 'is_stok' => 'Y']);
find_or_404(where)

This method is exactly same as the find() method but if the return value is null then it will appear 404 page

insert(data)
Param Type Required Description
data Array Yes Data to insert

~ Example 1: Insert one row

$this->My_model_name->insert([
  'field_name_1' => 'test1', 
  'field_name_2' => 'Testing1'
]);

~ Example 2: Insert multiple row bulk

$insert = [];
$insert[] = ['field_name_1' => 'test1', 'field_name_2' => 'Testing1'];
$insert[] = ['field_name_1' => 'test2', 'field_name_2' => 'Testing2'];
$this->My_model_name->insert($insert);
update(where, set)
Param Type Required Description
where Array Yes Specific data to be updated
set Array Yes Column & value to be updated
$this->My_model_name->update(['my_primary_key' => '1'], ['my_field_name' => 'new value']);
updateIncrement(where, field_name)
Param Type Required Description
where Array Yes Specific data to be updated
field_name String Yes Column & value to be updated
$this->My_model_name->updateIncrement(
	['kode_produk' => 'INV-202004-0001'],
	'jumlah_stok'
);

If the value of field jumlah_stok is 10 then the new value is 11

updateDecrement(where, field_name)
Param Type Required Description
where Array Yes Specific data to be updated
field_name String Yes Column & value to be updated
$this->My_model_name->updateDecrement(
	['kode_produk' => 'INV-202004-0001'],
	'jumlah_stok'
);

If the value of field jumlah_stok is 10 then the new value is 9

delete(where)
Param Type Required Description
where Array or Integer or String Yes Specific data to be deleted

~ Example 1: where clause on primary key

$this->My_model_name->delete('INV-202004-0001');

~ Example 2: where custom field clause

$this->My_model_name->delete(['my_primary_key' => 'value']);
primaryKeyInc()

If you're using this method. You must define your field primary key on property model

<?php defined('BASEPATH') OR exit('No direct script access allowed');

use Eloquent\Eloquent;

class My_model_name extends Eloquent
{

  public $table = 'my_table_name';
  public $primary_key = 'my_field_name_id';

  public function __construct()
  {
    parent::__construct();
  }

}

Then, you can using this method & get the increment

$increment = $this->My_model_name->primaryKeyInc();
primaryKey([opts])

Firstly, The same as the primaryKeyInc() method, you must define your field primary key on property model

Param Type Required Description
format String Yes Prefix for generate code, take it for example: If you want the return value is INV/202010/0001 so the format is INV
separator String No Separator for generate code, take it for example: If you want the return value is INV-202010-0001 so the separator is -
digit_inc Integer No Digit increment, Default value: 4
reset_monthly Boolean No Fill yearmonth in return value & reset the increment every month changed. Default value: TRUE

~ Example 1: Generate code & reset increment every month

  $pk = $this->My_model_name->primaryKey([
    "format" => "INV", 
    "separator" => "-",
    "digit_inc" => 5
  ]);

  # return value is: INV-202010-00001

~ Example 2: Generate code & non reset increment

  $pk = $this->My_model_name->primaryKey([
    "format" => "KTG", 
    "separator" => "",
    "digit_inc" => 6,
    "reset_monthly" => FALSE
  ]);

  # return value is: KTG000001

LICENSE

Usage is provided under the MIT License. See LICENSE for the full details.

maika-kanaka/ci3-eloquent 适用场景与选型建议

maika-kanaka/ci3-eloquent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 101 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 maika-kanaka/ci3-eloquent 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-20