tomkirsch / crud
CRUD Library for CI4
Installs: 76
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tomkirsch/crud
Requires
- php: ^7.3||^8.0
- codeigniter4/framework: ^4
- dev-master
- v1.11.0
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.23
- v1.9.22
- v1.9.21
- v1.9.20
- v1.9.19
- v1.9.18
- v1.9.17
- v1.9.16
- v1.9.15
- v1.9.14
- v1.9.13
- v1.9.12
- v1.9.11
- 1.9.10
- v1.9.7
- v1.9.6
- v1.9.5
- v1.9.4
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2026-02-28 05:33:08 UTC
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.phpBaseEntity.phpdate_helper.phpform_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
$allowedFieldsfrom$validationRules columns()helper based on validation rulesnextAutoIncrement()(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/entitiesprefixMap()--- extracts prefixed join fields into sub-entitiesstripAliasPrefix()--- removes select alias prefixesgetHtmlData()--- exports entity attributes as HTMLdata-*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.