PHPackages                             tomkirsch/crud - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. tomkirsch/crud

ActiveLibrary[Framework](/categories/framework)

tomkirsch/crud
==============

CRUD Library for CI4

v1.11.0(1y ago)079PHPPHP ^7.3||^8.0

Since Jan 26Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/tomkirsch/ci4-crud)[ Packagist](https://packagist.org/packages/tomkirsch/crud)[ RSS](/packages/tomkirsch-crud/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (1)Versions (41)Used By (0)

ci4-crud
========

[](#ci4-crud)

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
--------

[](#contents)

- `BaseModel.php`
- `BaseEntity.php`
- `date_helper.php`
- `form_helper.php`

---

BaseModel
---------

[](#basemodel)

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

### Key Features

[](#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

[](#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

[](#sync-lookup-tables)

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

Handles insert + delete diff automatically.

---

BaseEntity
----------

[](#baseentity)

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

### Key Features

[](#key-features-1)

- `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
------------

[](#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
------------

[](#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
------------

[](#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
-----

[](#notes)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance60

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~51 days

Total

40

Last Release

613d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.2

v1.10.0PHP ^7.3||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/362359?v=4)[Thomas Kirsch](/maintainers/tkirsch)[@tkirsch](https://github.com/tkirsch)

---

Top Contributors

[![tomkirsch](https://avatars.githubusercontent.com/u/36715955?v=4)](https://github.com/tomkirsch "tomkirsch (54 commits)")

### Embed Badge

![Health badge](/badges/tomkirsch-crud/health.svg)

```
[![Health](https://phpackages.com/badges/tomkirsch-crud/health.svg)](https://phpackages.com/packages/tomkirsch-crud)
```

###  Alternatives

[codeigniter4/appstarter

CodeIgniter4 starter app

1781.8M](/packages/codeigniter4-appstarter)[abydahana/aksara

Aksara is a CodeIgniter based CRUD Toolkit you can use to build complex applications become shorter, secure and more reliable just in a few lines of code. Serving both CMS or Framework, produce both HEADLESS (RESTful API) or TRADITIONAL (Browser Based), just by writing single controller. Yet it's reusable, scalable and ready to use!

1111.2k](/packages/abydahana-aksara)[irsyadulibad/codeigniter4-datatables

Server side DataTables library for CodeIgniter4 framework

702.5k](/packages/irsyadulibad-codeigniter4-datatables)[mufidjamaluddin/codeigniter4-hmvc

CodeIgniter4 HMVC starter app

672.0k](/packages/mufidjamaluddin-codeigniter4-hmvc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
