tomkirsch/crud 问题修复 & 功能扩展

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

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

tomkirsch/crud

Composer 安装命令:

composer require tomkirsch/crud

包简介

CRUD Library for CI4

README 文档

README

A focused set of base classes and helpers for building structured CRUD applications in CodeIgniter 4.
Designed to reduce repetition in models, entities, joins, form handling, and timezone-aware date workflows.

Contents

  • BaseModel.php
  • BaseEntity.php
  • date_helper.php
  • form_helper.php

BaseModel

Extends CodeIgniter\Model and adds higher-level utilities for relational CRUD workflows.

Key Features

  • Automatic prefixing of primary/created/updated/deleted fields
  • Option to derive $allowedFields from $validationRules
  • columns() helper based on validation rules
  • nextAutoIncrement() (MySQL information_schema lookup)
  • Smart save() override (prevents empty PK from forcing update)
  • syncOneToMany() for maintaining lookup tables
  • Join utilities with automatic unique field aliasing
  • Subquery helpers for selecting values from latest related rows

Join Workflow

joinModel() registers fields with unique aliases.
selectUnique() builds a collision-safe SELECT clause.

Example:

$rows = $userModel
    ->reset()
    ->joinModel('ProfileModel', 'profiles.user_id = users.id', 'left')
    ->selectUnique()
    ->findAll();

Supports aliasing and prefix mapping for nested joins.

Sync Lookup Tables

$model->syncOneToMany(
    'foos2bars',
    ['foo_id' => 1],
    'bar_id',
    [12, 13],
    [5, 13, 14]
);

Handles insert + delete diff automatically.

BaseEntity

Extends CodeIgniter\Entity\Entity and improves form and join handling.

Key Features

  • fillNullEmpty() --- converts empty strings to NULL before fill
  • Timezone helpers:
    • applyLocalTimezone()
    • applyServerTimezone()
  • csvMap() --- converts GROUP_CONCAT CSV fields into structured objects/entities
  • prefixMap() --- extracts prefixed join fields into sub-entities
  • stripAliasPrefix() --- removes select alias prefixes
  • getHtmlData() --- exports entity attributes as HTML data-* attributes

Example:

$image = $row->prefixMap('image_', \App\Entities\Image::class, true);

date_helper

Helpers for timezone-aware date handling using CodeIgniter\I18n\Time.

Functions:

  • localDate($dateTime, $format = null, $timezone = null)
  • serverDate($dateTime, $format = null, $timezone = null)

Supports returning either a Time object or formatted string.

Requires:

public string $localTimezone;
public string $appTimezone;

in Config/App.php.

form_helper

Improves CI form value binding for objects/entities.

Handles:

  • NULL vs empty
  • Boolean fields
  • DateTime / Time objects
  • Bracketed input names (user[email])
  • Optional local timezone conversion

Key functions:

  • set_value_from()
  • set_checkbox_from()
  • set_select_from()
  • set_radio_from()
  • set_textarea_from()

Example:

echo form_input('email', set_value_from('email', $user));

With date formatting:

echo form_input('starts_at', set_value_from('starts_at', $entity, '', true, [
    'localTimezone' => true,
    'format' => 'Y-m-d H:i:s',
]));

Installation

Drop the classes into an autoloaded namespace and register via PSR-4 in Config/Autoload.php.

Place helpers in app/Helpers/ and load with:

helper(['date', 'form']);

Notes

  • Call reset() when using the unique join workflow before building a new query.
  • Ensure syncOneToMany() receives specific WHERE conditions in $common_data.

tomkirsch/crud 适用场景与选型建议

tomkirsch/crud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 tomkirsch/crud 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-01-26