PHP code example of rougin / credo

1. Go to this page and download the library: Download rougin/credo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rougin / credo example snippets

 php
// 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;

    // ...
}
 php
// 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());
 php
// application/core/MY_Loader.php

class MY_Loader extends \Rougin\Credo\Loader
{
}
 php
// application/repositories/User_repository.php

use Rougin\Credo\Repository;

class User_repository extends Repository
{
    public function find_by_something()
    {
        // ...
    }
}
 php
// 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();
 php
// 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;

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

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

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

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

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