Doctrine ORM integration for the Codeigniter framework

Credo is a simple PHP library that uses Doctrine ORM into the Codeigniter framework for managing database logic.

View source code on Github

Credo is a packages that acts as a wrapper of Doctrine ORM to a Codeigniter 3 project. This package was created based on the official integration for Codeigniter 3 to the Doctrine package.

Installation

Install Credo through Composer:

$ composer require rougin/credo

Basic Usage

Create any model that conforms to the Doctrine documentation:

// application/models/User.php

/**
 * @Entity
 * @Table(name="user")
 */
class User extends CI_Model
{
    /**
     * @Id @GeneratedValue
     * @Column(name="id", type="integer", length=10, nullable=FALSE, unique=FALSE)
     * @var integer
     */
    protected $_id;

    // ...
}
// application/controllers/Welcome.php

$this->load->model('user');

$this->load->database();

$credo = new Rougin\Credo\Credo($this->db);

$repository = $credo->get_repository('User');

$user = $repository->findBy(array());

Using Rougin\Credo\Repository

To enable this package on a Codeigniter 3 project, extend Rougin\Credo\Loader to MY_Loader first:

// application/core/MY_Loader.php

class MY_Loader extends \Rougin\Credo\Loader
{
}

Then use the suffix _repository for creating repositories (e.g., User_repository):

// application/repositories/User_repository.php

use Rougin\Credo\Repository;

class User_repository extends Repository
{
    public function find_by_something()
    {
        // ...
    }
}

And lastly is to load the specified repository using $this->load->repository:

// application/controllers/Welcome.php

$this->load->model('user');

// Loads the customized repository ---
$this->load->repository('user');
// -----------------------------------

$this->load->database();

$credo = new Rougin\Credo\Credo($this->db);

$repository = $credo->get_repository('User');

$users = $repository->find_by_something();

[!NOTE] For more information about repositories in Doctrine, please check its documentation.

Using Rougin\Credo\Model

// application/models/User.php

/**
 * @Entity
 * @Table(name="user")
 */
class User extends \Rougin\Credo\Model
{
    /**
     * @Id @GeneratedValue
     * @Column(name="id", type="integer", length=10, nullable=FALSE, unique=FALSE)
     * @var integer
     */
    protected $_id;

    // ...
}
// application/controllers/Welcome.php

$this->load->model('user', '', TRUE);

$credo = new Rougin\Credo\Credo($this->db);

$this->user->credo($credo);

$users = $this->user->get();

Migrating to the v0.5.0 release

The new release for v0.5.0 will be having a backward compatibility break (BC break). With this, some functionalities from the earlier versions might not be working after upgrading. This was done to increase the maintainability of the project while also adhering to the functionalities for both Codeigniter 3 and Doctrine ORM. Please see the UPGRADING page for the said breaking changes.

[!TIP] If still using the v0.4 release, kindly click its documentation below: https://github.com/rougin/credo/blob/v0.4.0/README.md