PHPackages                             daycry/doctrine - 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. [Database &amp; ORM](/categories/database)
4. /
5. daycry/doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

daycry/doctrine
===============

Doctrine for Codeigniter 4

v5.1.0(3w ago)93.1k↓73.3%3MITPHPPHP &gt;=8.2CI passing

Since Apr 5Pushed 3w ago2 watchersCompare

[ Source](https://github.com/daycry/doctrine)[ Packagist](https://packagist.org/packages/daycry/doctrine)[ Docs](https://github.com/daycry/doctrine)[ RSS](/packages/daycry-doctrine/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (50)Versions (61)Used By (0)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/donate?business=SYC5XDT23UZ5G&no_recurring=0&item_name=Thank+you%21&currency_code=EUR)

Doctrine
========

[](#doctrine)

Doctrine ORM 3 integration for CodeIgniter 4.

[![PHPUnit](https://github.com/daycry/doctrine/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/daycry/doctrine/actions/workflows/phpunit.yml)[![PHPStan](https://github.com/daycry/doctrine/actions/workflows/phpstan.yml/badge.svg?branch=master)](https://github.com/daycry/doctrine/actions/workflows/phpstan.yml)[![Psalm](https://github.com/daycry/doctrine/actions/workflows/psalm.yml/badge.svg?branch=master)](https://github.com/daycry/doctrine/actions/workflows/psalm.yml)[![Rector](https://github.com/daycry/doctrine/actions/workflows/rector.yml/badge.svg?branch=master)](https://github.com/daycry/doctrine/actions/workflows/rector.yml)[![Code Style](https://github.com/daycry/doctrine/actions/workflows/cs.yml/badge.svg?branch=master)](https://github.com/daycry/doctrine/actions/workflows/cs.yml)[![Coverage Status](https://camo.githubusercontent.com/572ed598621b543f78e1cfb5dbeb5c3f9f6c679c2ac5d876afd34693f3f70742/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6461796372792f646f637472696e652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/daycry/doctrine?branch=master)[![Downloads](https://camo.githubusercontent.com/07c1616b587182f7cdd29c6014f806703e53166295eb91566bf5de2e6516f9d8/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f646f637472696e652f646f776e6c6f616473)](https://packagist.org/packages/daycry/doctrine)[![Monthly Downloads](https://camo.githubusercontent.com/3626570619432013d9544c2989eb04cdcf387ac8ed48032472e5c6146669ba9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6461796372792f646f637472696e65)](https://packagist.org/packages/daycry/doctrine)[![GitHub release (latest by date)](https://camo.githubusercontent.com/9a3cde787353f729d763a8ad00f4dde2a61195fefc662b8bd13cfe7d96796fe5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6461796372792f646f637472696e65)](https://packagist.org/packages/daycry/doctrine)[![GitHub stars](https://camo.githubusercontent.com/65624aafde73aafc2ca8ff2794003c6750b7d6465012a54f4c8f832b95e6a1bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6461796372792f646f637472696e65)](https://packagist.org/packages/daycry/doctrine)[![GitHub license](https://camo.githubusercontent.com/9281881ec173a3bd06af0f8e455440339470dac0d590353862aba9cffc6f549b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6461796372792f646f637472696e65)](https://github.com/daycry/doctrine/blob/master/LICENSE)[![Documentation](https://camo.githubusercontent.com/9cc11f8dbe6b0e0265c425f72be57d58f71679990fae12ad58ccb051e73fd598/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d6461796372792e6769746875622e696f253246646f637472696e652d626c75653f6c6f676f3d6d6174657269616c666f726d6b646f6373266c6f676f436f6c6f723d7768697465)](https://daycry.github.io/doctrine/)

📖 **Documentation:**

Features
--------

[](#features)

- ORM integration via `\Daycry\Doctrine\Doctrine` and `\Config\Services::doctrine()`.
- Server-side **DataTables Builder** with safe operator parsing, whitelisted columns, and `[>em->getRepository(\App\Models\Entity\User::class)->find(1);
```

### As a helper

[](#as-a-helper)

Add `doctrine_helper` to your `BaseController::$helpers`:

```
protected $helpers = ['doctrine_helper'];
```

```
$doctrine  = doctrine_instance();             // default DB group
$reporting = doctrine_instance('reporting');  // alternate DB group
```

### Constructing manually

[](#constructing-manually)

```
$doctrine = new \Daycry\Doctrine\Doctrine();
$user     = $doctrine->em->getRepository(\App\Models\Entity\User::class)->find(1);
```

Manual Result Caching
---------------------

[](#manual-result-caching)

`getFromCacheOrQuery()` is autoloaded as a global function (no `use` is needed beyond the function import). It looks up `$cacheKey` in the configured result cache pool and falls back to the closure on miss.

```
use function Daycry\Doctrine\Helpers\getFromCacheOrQuery;

$rows = getFromCacheOrQuery(
    cacheKey: 'projects_list_v1',
    ttl: 300,
    queryFn: fn () => $doctrine->em
        ->createQueryBuilder()
        ->select('p')
        ->from(\App\Models\Entity\Project::class, 'p')
        ->getQuery()
        ->getArrayResult(),
);
```

When the result cache is disabled (`Config\Doctrine::$resultsCache = false`) the closure runs every time. PSR-6 reserved characters (`{}()/\@:`) in the key are normalised automatically, so any key string is accepted.

See [docs/usage.md](docs/usage.md) for advanced API: `getEm()`, `reOpen()`, multi-database groups, `Services::resetDoctrine()`, and more.

Doctrine ORM CLI
----------------

[](#doctrine-orm-cli)

Use the generated `cli-config.php` from the project root:

```
php cli-config.php orm:validate-schema          # check mappings vs. database
php cli-config.php orm:schema-tool:update --dump-sql   # preview schema changes
php cli-config.php orm:schema-tool:update --force      # apply them
php cli-config.php orm:generate-proxies app/Models/Proxies
php cli-config.php orm:info                      # list mapped entities
php cli-config.php orm:run-dql "SELECT u FROM App\Models\Entity\User u"
```

> Doctrine ORM 3 removed `orm:convert-mapping` and `orm:generate-entities`. Reverse-engineering an existing schema into entities is no longer part of the ORM toolchain; map your entities with PHP attributes (or XML) directly.

The same commands are also available through Spark — see [docs/cli\_commands.md](docs/cli_commands.md).

DataTables
----------

[](#datatables)

```
$datatables = (new \Daycry\Doctrine\DataTables\Builder())
    ->withColumnAliases([
        'id'   => 'p.id',
        'name' => 'p.name',
    ])
    ->withSearchableColumns(['p.name'])
    ->withCaseInsensitive(true)
    ->withMaxFilterValues(500) // cap [IN] / [OR] value lists; default 500
    ->withMaxPageLength(200)   // cap page size; clamps length=-1 ("All") — default 0 (no cap)
    ->withQueryBuilder(
        $this->doctrine->em->createQueryBuilder()
            ->select('p.id, p.name')
            ->from(\App\Models\Entity\Project::class, 'p'),
    )
    ->withRequestParams($this->request->getGet());

return $this->response->setJSON($datatables->getResponse());
```

If pagination throws *"Not all identifier properties can be found in the ResultSetMapping"*, set `->setUseOutputWalkers(false)` on the Builder.

### Search modes

[](#search-modes)

The Builder supports bracket-prefixed operators per column:

```
[%]   (LIKE, default)   [=]   [!=]   [>]   [setMaxQueries(500); // FIFO; 0 disables the cap
```

See [docs/debug\_toolbar.md](docs/debug_toolbar.md) for the full collector API, the SLC stats badge, and the per-request reset filter.

Second-Level Cache (SLC)
------------------------

[](#second-level-cache-slc)

Doctrine's Second-Level Cache reuses the framework cache backend (file / Redis / Memcached / array) and its `ttl`. Enable in `app/Config/Doctrine.php`:

```
public bool $secondLevelCache           = true;
public bool $secondLevelCacheStatistics = true;  // optional: hits/misses/puts badge
public ?int $secondLevelCacheTtl        = null;   // null = inherit Config\Cache::$ttl; 0 = no expiry
```

To reset SLC statistics at the start of every request (useful in development to read per-request hit ratios in the toolbar), register the filter:

```
// app/Config/Filters.php
public array $globals = [
    'before' => [
        \Daycry\Doctrine\Debug\Filters\DoctrineSlcReset::class,
    ],
];
```

The filter is a no-op unless `secondLevelCacheStatistics` is enabled.

See [docs/second\_level\_cache.md](docs/second_level_cache.md) and [docs/second\_level\_cache\_stats.md](docs/second_level_cache_stats.md) for full details.

Extending the EntityManager
---------------------------

[](#extending-the-entitymanager)

`Config\Doctrine` exposes additive, backward-compatible hooks (all default to off) for the common Doctrine extension points:

```
// app/Config/Doctrine.php
public array  $customTypes            = ['uuid' => \Ramsey\Uuid\Doctrine\UuidType::class];
public array  $sqlFilters             = ['soft_delete' => \App\Doctrine\SoftDeleteFilter::class];
public array  $enabledFilters         = ['soft_delete'];
public array  $eventListeners         = ['onFlush' => [\App\Doctrine\AuditListener::class]];
public array  $eventSubscribers       = [\App\Doctrine\TimestampSubscriber::class];
public array  $dbalMiddlewares        = [\App\Doctrine\RetryMiddleware::class];
public ?string $defaultRepositoryClass = \App\Repositories\BaseRepository::class;

// Production query logging (PSR-3) — independent of the debug toolbar
public bool   $queryLogging        = true;
public float  $slowQueryThreshold  = 0.5;  // log queries slower than 500 ms
public string $queryLogLevel       = 'warning';
```

All are re-applied across `Doctrine::reOpen()`. See [docs/configuration.md](docs/configuration.md#extension-points) for the full reference.

Development
-----------

[](#development)

Available Composer scripts for contributors:

```
composer test          # PHPUnit test suite
composer phpstan       # PHPStan (level 6)
composer psalm         # Psalm static analysis
composer rector        # Rector dry-run
composer analyze       # phpstan + psalm + rector
composer cs            # PHP-CS-Fixer dry-run
composer cs-fix        # PHP-CS-Fixer apply
```

License
-------

[](#license)

[MIT](LICENSE.md). Issues and PRs welcome at .

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance94

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97.8% 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 ~41 days

Total

56

Last Release

27d ago

Major Versions

v1.4.5 → v2.0.02022-08-10

v2.0.2 → v3.0.02023-05-15

v3.0.4 → v4.0.02024-03-04

v4.2.0 → v5.0.02026-05-07

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

v1.4.0PHP &gt;=7.2 || ^8.0

v1.4.1PHP ^7.2 || ^8.0

v2.0.0PHP ^7.4 || ^8.0

v3.0.3PHP &gt;=8.1

v4.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b0f66565d5c9ca3c84fb294e04f8d5e0b9a867d9c06f83b95bf168bd6fcf9bc?d=identicon)[daycry](/maintainers/daycry)

---

Top Contributors

[![daycry](https://avatars.githubusercontent.com/u/7590335?v=4)](https://github.com/daycry "daycry (178 commits)")[![agung-wete](https://avatars.githubusercontent.com/u/4055492?v=4)](https://github.com/agung-wete "agung-wete (4 commits)")

---

Tags

ormmysqldoctrinecodeigniterdatatablescodeigniter4

### Embed Badge

![Health badge](/badges/daycry-doctrine/health.svg)

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M386](/packages/easycorp-easyadmin-bundle)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8465.5M96](/packages/laravel-doctrine-orm)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M203](/packages/sulu-sulu)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58825.9M54](/packages/scienta-doctrine-json-functions)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)

PHPackages © 2026

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