Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 25, 2018
1 parent 60de446 commit fcb2e79
Showing 1 changed file with 147 additions and 10 deletions.
157 changes: 147 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ $credo = new Rougin\Credo\Credo($this->db);

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

$user = $repository->find(4);
$user = $repository->findBy(array());
```

### Using `Rougin\Credo\EntityRepository`
### Using `Rougin\Credo\Repository`

Extend `Rougin\Credo\Loader` to `MY_Loader`:

Expand All @@ -69,14 +69,14 @@ Kindly also use the suffix `_repository` for creating repositories. (e.g. `User_
``` php
// application/repositories/User_repository.php

use Rougin\Credo\EntityRepository;
use Rougin\Credo\Repository;

class User_repository extends EntityRepository {
class User_repository extends Repository {

public function find_by_something()
{
// ...
}
public function find_by_something()
{
// ...
}

}
```
Expand All @@ -88,6 +88,7 @@ Then load the repository using `$this->load->repository($repositoryName)`.

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

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

$this->load->database();
Expand All @@ -101,7 +102,7 @@ $users = $repository->find_by_something();

For more information about repositories in Doctrine, please check its [documentation](http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#custom-repositories).

### Using `Rougin\Credo\CodeigniterModel`
### Using `Rougin\Credo\Model`

``` php
// application/models/User.php
Expand All @@ -110,7 +111,7 @@ For more information about repositories in Doctrine, please check its [documenta
* @Entity
* @Table(name="user")
*/
class User extends \Rougin\Credo\CodeigniterModel {
class User extends \Rougin\Credo\Model {

/**
* @Id @GeneratedValue
Expand All @@ -129,9 +130,145 @@ class User extends \Rougin\Credo\CodeigniterModel {

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

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

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

## Migrating to the `v0.5.0` release

The new release for `v0.5.0` will be having a [backward compatibility](https://en.wikipedia.org/wiki/Backward_compatibility) break (BC break). So some functionalities on the earlier versions might not be working after updating. This was done to increase the maintainability of the project while also adhering to the functionalities for both Codeigniter and Doctrine ORM. To check the documentation for the last release (`v0.4.0`), kindly click [here](https://github.com/rougin/credo/blob/v0.4.0/README.md).

### Change the `CodeigniterModel` class to `Model` class

**Before**

``` php
class User extends \Rougin\Credo\CodeigniterModel {}
```

**After**

``` php
class User extends \Rougin\Credo\Model {}
```

### Change the `EntityRepository` class to `Repository` class

**Before**

``` php
class User extends \Rougin\Credo\EntityRepository {}
```

**After**

``` php
class User extends \Rougin\Credo\Repository {}
```

### Set `Credo` instance manually to `Model`

**Before**

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

**After**

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

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

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

All Credo functionalities are now moved to `CredoTrait` which is can be added on existing models.

### Change the arguments for `PaginateTrait::paginate`

**Before**

``` php
// PaginateTrait::paginate($perPage, $config = array())
list($result, $links) = $this->user->paginate(5, $config);
```

**After**

``` php
$total = $this->db->count_all_results('users');

// PaginateTrait::paginate($perPage, $total, $config = array())
list($offset, $links) = $this->user->paginate(5, $total, $config);
```

The total count must be passed in the second parameter.

### Remove `Model::countAll`

**Before**

``` php
$total = $this->user->countAll();
```

**After**

``` php
$total = $this->db->count_all_results('users');
```

This is being used only in `PaginateTrait::paginate`.

### Change the method `ValidateTrait::validationErrors` to `ValidateTrait::errors`

**Before**

``` php
ValidateTrait::validationErrors()
```

**After**

``` php
ValidateTrait::errors()
```

### Change the property `Model::validation_rules` to `ValidateTrait::rules`

**Before**

``` php
// application/models/User.php

protected $validation_rules = array();
```

**After**

``` php
// application/models/User.php

protected $rules = array();
```

### Change the method `Model::all` to `Model::get`

**Before**

``` php
$users = $this->user->all();
```

**After**

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

## Change Log

Please see [CHANGELOG][link-changelog] for more information what has changed recently.
Expand Down

0 comments on commit fcb2e79

Please sign in to comment.