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

v4.1.14(2mo ago)93.0k↓22.2%3MITPHPPHP &gt;=8.2CI passing

Since Apr 5Pushed 5mo 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 1mo ago

READMEChangelog (10)Dependencies (24)Versions (54)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 for Codeigniter 4

[![Build Status](https://github.com/daycry/doctrine/workflows/PHP%20Tests/badge.svg)](https://github.com/daycry/doctrine/actions?query=workflow%3A%22PHP+Tests%22)[![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)[![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 Index
-------------------

[](#documentation-index)

- [Installation](docs/installation.md)
- [Configuration](docs/configuration.md)
- [Usage](docs/usage.md)
- [CLI Commands](docs/cli_commands.md)
- [Using DataTables](docs/datatables.md)
    - Filtering operators and search behavior documented in `docs/datatables.md`.
- [DataTables Search Modes](docs/search_modes.md)
- [Viewing Doctrine Queries in the Debug Toolbar](docs/debug_toolbar.md)
- [Second-Level Cache (SLC)](docs/second_level_cache.md) — Enable Doctrine entity caching across requests. SLC uses the same cache backend configured in CodeIgniter (`Config\Cache`) and its `ttl`; toggle on/off in `Config\Doctrine`.
- [SLC Statistics](docs/second_level_cache_stats.md) — How to enable hits/misses/puts counters and view them in the Debug Toolbar.

Installation via composer
-------------------------

[](#installation-via-composer)

Use the package with composer install

```
> composer require daycry/doctrine

```

Configuration
-------------

[](#configuration)

Run command:

```
> php spark doctrine:publish

```

This command will copy a config file to your app namespace and "cli-config.php" file for doctrine cli. Then you can adjust it to your needs. By default file will be present in `app/Config/Doctrine.php`.

Usage Loading Library
---------------------

[](#usage-loading-library)

```
$doctrine = new \Daycry\Doctrine\Doctrine();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );
```

Usage as a Service
------------------

[](#usage-as-a-service)

```
$doctrine = \Config\Services::doctrine();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );
```

Usage as a Helper
-----------------

[](#usage-as-a-helper)

In your BaseController - $helpers array, add an element with your helper filename.

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

And then, you can use the helper

```
$doctrine = doctrine_instance();
$data = $doctrine->em->getRepository( 'App\Models\Entity\Class' )->findOneBy( array( 'id' => 1 ) );
var_dump( $data );
```

Cli Commands
------------

[](#cli-commands)

```
//Mapping de database to entities classes
php cli-config.php orm:convert-mapping --namespace="App\Models\Entity\" --force --from-database annotation .

//Generate getters & setters
php cli-config.php orm:generate-entities .

//Generate proxy classes
php cli-config.php orm:generate-proxies app/Models/Proxies
```

If you receive the followrin error: **\[Semantical Error\] The annotation "@JMS\\Serializer\\Annotation\\ExclusionPolicy" in class App\\Models\\Entity\\Secret was never imported. Did you maybe forget to add a "use" statement for this annotation?**

You must execute the following command

```
    composer dump-autoload
```

Using DataTables
----------------

[](#using-datatables)

Usage with [doctrine/orm](https://github.com/doctrine/doctrine2):
-----------------------------------------------------------------

[](#usage-with-doctrineorm)

```
$datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 'qlu.id'
                ]
            )
            ->withIndexColumn( 'qlu.id' )
            ->withQueryBuilder(
                $this->doctrine->em->createQueryBuilder()
                    ->select( 'qlu.param, q.param, q.param, qs.id as param, qlu.param, qlu.param' )
                    ->from( \App\Models\Entity\Class::class, 'qlu' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'qs', \Doctrine\ORM\Query\Expr\Join::WITH, 'qs.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'ql', \Doctrine\ORM\Query\Expr\Join::WITH, 'ql.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'q', \Doctrine\ORM\Query\Expr\Join::WITH, 'q.id = ql.*' )
            )
            ->withRequestParams( $this->request->getGet( null ) );

        $response = $datatables->getResponse();

        echo \json_encode( $response );
```

If you receive an error: **Not all identifier properties can be found in the ResultSetMapping** you can use:

```
    ->setUseOutputWalkers( false )
```

Example
-------

[](#example)

```
$datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 'qlu.id'
                ]
            )
            ->withIndexColumn( 'qlu.id' )
            ->setUseOutputWalkers( false )
            ->withQueryBuilder(
                $this->doctrine->em->createQueryBuilder()
                    ->select( 'qlu.param, q.param, q.param, qs.id as param, qlu.param, qlu.param' )
                    ->from( \App\Models\Entity\Class::class, 'qlu' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'qs', \Doctrine\ORM\Query\Expr\Join::WITH, 'qs.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'ql', \Doctrine\ORM\Query\Expr\Join::WITH, 'ql.id = qlu.*' )
                    ->innerJoin( \App\Models\Entity\Class::class, 'q', \Doctrine\ORM\Query\Expr\Join::WITH, 'q.id = ql.*' )
            )
            ->withRequestParams( $this->request->getGet( null ) );

        $response = $datatables->getResponse();

        echo \json_encode( $response );
```

Search
------

[](#search)

To search from datatables there are nine different search modes

ModePatternDesctiption**LIKE '…%'**\[\*%\]searchTermThis performs a LIKE '…%' search where the start of the search term must match a value in the given column. This can be archived with only providing the search term (because it's default) or by prefixing the search term with "\[*%\]" (\[*%\]searchTerm).**LIKE '%…%'**\[%%\]searchTermThis performs a LIKE '%…%' search where any part the search term must match a value in the given column. This can be archived by prefixing the search term with "\[%%\]" (\[%%\]searchTerm).**Equality**\[=\]searchTermThis performs a = … search. The search term must exactly match a value in the given column. This can be archived by prefixing the search term with "\[=\]" (\[=\]searchTerm).**!= (No Equality)**\[!=\]searchTermThis performs a != … search. The search term must not exactly match a value in the given column. This can be archived by prefixing the search term with "\[!=\]" (\[!=\]searchTerm).**&gt;** (Greater Than)\[&gt;\]searchTermThis performs a &gt; … search. The search term must be smaller than a value in the given column. This can be archived by prefixing the search term with "\[&gt;\]" (\[&gt;\]searchTerm).**&lt;** (Smaller Than)\[&lt;\]searchTermThis performs a &lt; … search. The search term must be greater than a value in the given column. This can be archived by prefixing the search term with "\[&lt;\]" (\[&lt;\]searchTerm).**&lt; (IN)**\[IN\]searchTerm,searchTerm,…This performs an IN(…) search. One of the provided comma-separated search terms must exactly match a value in the given column. This can be archived by prefixing the search terms with "\[IN\]" (\[IN\]searchTerm,searchTerm,…).**&lt; (OR)**\[OR\]searchTerm,searchTerm,…This performs multiple OR-connected LIKE('%…%') searches. One of the provided comma-separated search terms must match a fragment of a value in the given column. This can be archived by prefixing the search terms with "\[OR\]" (\[OR\]searchTerm,searchTerm,…).**&gt;&lt; (Between)**\[&gt;&lt;\]searchTerm,searchTermThis performs a BETWEEN … AND … search. Both search terms must be separated with a comma. This operation can be archived by prefixing the comma-separated search terms with "\[&gt;&lt;\]" (\[&gt;&lt;\]searchTerm,searchTerm).Prefixes are case-insenstive (IN, in, OR, or). Provided search terms were trimmed.

Example
-------

[](#example-1)

```
public function testDataTableSearchColumnWithOr()
    {
        $doctrine = new \Daycry\Doctrine\Doctrine($this->config);
        $request = \Config\Services::request();

        $datatables = ( new \Daycry\Doctrine\DataTables\Builder() )
            ->withColumnAliases(
                [
                    'id' => 't.id',
                    'name' => 't.name'
                ]
            )
            ->withIndexColumn('qlu.id')
            ->setUseOutputWalkers(false)
            ->withCaseInsensitive(false)
            ->withColumnField('name')
            ->withQueryBuilder(
                $doctrine->em->createQueryBuilder()
                    ->select('t.id, t.name')
                    ->from(\Tests\Support\Models\Entities\Test::class, 't')
            )
            ->withRequestParams(
                array(
                    'draw' => 1,
                    'start' => 0,
                    'length' => 10,
                    'search' => array('value' => '', 'regex' => true ),
                    'columns' => array(
                        array(
                            'data' => 'id',
                            'name' => 'id',
                            'searchable' => true,
                            'orderable' => true,
                            'search' => array('value' => '[OR]1,3', 'regex' => false)
                        ),
                        array(
                            'data' => 'name',
                            'name' => 'name',
                            'searchable' => true,
                            'orderable' => true,
                            'search' => array('value' => '', 'regex' => false)
                        )
                    ),
                    'order' => array( array( 'column' => 0, 'dir' => 'asc') )
                )
            );

        echo $response = json_encode($datatables->getResponse());

    }
```

Viewing Doctrine Queries in the Debug Toolbar
---------------------------------------------

[](#viewing-doctrine-queries-in-the-debug-toolbar)

This library allows you to view all SQL queries executed by Doctrine directly in the CodeIgniter 4 Debug Toolbar, making it easier to analyze and debug your database interactions.

### How does it work?

[](#how-does-it-work)

- A custom Collector (`DoctrineCollector`) and Middleware (`DoctrineQueryMiddleware`) are included to capture all queries executed by Doctrine.
- The Middleware is automatically integrated when you instantiate `\Daycry\Doctrine\Doctrine`.
- The Collector exposes the query information to the Toolbar, letting you see queries in real time.

### Integration steps

[](#integration-steps)

1. **Register the Collector in the Toolbar**

    Open your `app/Config/Toolbar.php` file and add the Doctrine Collector to the `$collectors` array:

    ```
    public $collectors = [
        // ...other collectors...
        \Daycry\Doctrine\Debug\Toolbar\Collectors\DoctrineCollector::class,
    ];
    ```
2. **Use the Doctrine class as usual**

    When you instantiate `\Daycry\Doctrine\Doctrine` (as a service, helper, or manually), the Middleware is automatically enabled and queries will be captured.
3. **View queries in the Toolbar**

    Whenever you execute any query with Doctrine, you will see a new "Doctrine" tab in the CodeIgniter 4 Debug Toolbar, showing all SQL queries executed during the current request.

### Notes and troubleshooting

[](#notes-and-troubleshooting)

- You do not need to call any method manually to enable the Collector or Middleware.
- If you do not see the "Doctrine" tab in the Toolbar, make sure the Collector is registered in `Toolbar.php` and that the Toolbar is enabled in your environment.
- Fully compatible with advanced connections (SQLite3, SSL, custom options) and Doctrine DBAL 4+.

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

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

Doctrine's Second-Level Cache caches entities across requests. This library wires SLC based on `Config\Doctrine.php` without requiring app code changes.

- Enable via `secondLevelCache.enabled = true`.
- Choose adapter: `array` (default), `file`, `redis`, `memcached`, or supply a PSR-6 pool in `secondLevelCache.psr6Pool`.
- Tune lifetimes with `defaultLifetime` and `defaultLockLifetime`.

Example configuration:

```
public array $secondLevelCache = [
    'enabled' => true,
    'adapter' => 'redis',
    'defaultLifetime' => 3600,
    'defaultLockLifetime' => 60,
    'host' => '127.0.0.1',
    'port' => 6379,
];
```

When enabled, `src\Doctrine.php` sets up a `DefaultCacheFactory` with region lifetimes and a PSR-6 cache pool matching your adapter.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance78

Regular maintenance activity

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97% 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

Recently: every ~59 days

Total

53

Last Release

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

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

[scienta/doctrine-json-functions

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

58523.9M36](/packages/scienta-doctrine-json-functions)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[rougin/credo

Doctrine ORM wrapper for Codeigniter 3.

151.1k](/packages/rougin-credo)

PHPackages © 2026

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