Credo - Integrates Doctrine to CodeIgniter with ease |
Hello! I've created a library named Credo, a synonym of the word Doctrine (www.doctrine-project.org/projects/orm.html) , that integrates the Doctrine ORM easily in CodeIgniter. http://github.com/rougin/credo
Installation You can install it via Composer: Code: $ composer require rougin/credo NOTE: composer_autoload must be enabled in the application/config/config.php. Basic Usage application/models/User.php PHP Code: /** application/controllers/Welcome.php PHP Code: $this->load->model('user'); Using Doctrine's EntityRepository Extend Rougin\Credo\Loader to MY_Loader. application/core/MY_Loader.php PHP Code: class MY_Loader extends Rougin\Credo\Loader {} Kindly also use the suffix _repository for creating repositories. (e.g. User_repository) application/repositories/User_repository.php PHP Code: class User_repository extends Rougin\Credo\EntityRepository { NOTE: Extending your repository to Rougin\Credo\EntityRepository enables you to call its methods in underscore case. (e.g. find_all, find_by) You can now load a repository by using this code: $this->load->repository($repositoryName). application/controllers/Welcome.php PHP Code: $this->load->model('user'); For more information about repositories in Doctrine, you can find them here: http://doctrine-orm.readthedocs.org/proj...positories
Hi,
Don't know much about Doctrine, and congrats on the integration. But would it not be easier to just do this: Code: $user = $this->db->where('id', 4)->get('users'); Or is there something about Doctrine that I have missed? Paul.
Hello @PaulD,
I understand that the code you mentioned is much easier but for me, I just followed the specifications provided by the Doctrine ORM. What I did was I made some methods that can be called in underscore case since it is in the Style Guide of CodeIgniter such as getRepository to get_repository. I did also based my implementation from the Getting Started page of Doctrine ORM (http://docs.doctrine-project.org/project...arted.html).
So, you went through all that just to follow the style guide?... Why would you? If someone were to use Doctrine, why not use it the way that the user manual shows him/her? Why add complexity when there is no need?
Website: http://avenir.ro
Hello! Credo is now updated. It fixes some issues in declaring the Credo class.
|
Welcome Guest, Not a member yet? Register Sign In |