What is the best ORM to use with codeigniter (php framework) and why?
-
possible duplicate of [Which ORM for codeigniter?](http://stackoverflow.com/questions/3438198/which-orm-for-codeigniter) – BoltClock Dec 29 '10 at 23:08
5 Answers
As DrColossos suggests, Doctrine is a good and powerful ORM which can be fairly easily plugged into a CI application. For CodeIgniter 2 & Doctrine 2, you can use this tutorial on Setting up CodeIgniter 2 with Doctrine 2 the Right Way.
The question is very vague and depends completely on the use case.
Anyway, I prefer Doctrine over the built-in database access simply because I preferr writing the queries instead of working with (IMO strange way of) CI's DB access. This has a much more OO feeling than the CI implementation and it is very powerfull since it allows you to do the same things as with regular SQL (complex joins, sub-selects, more advanced WHERE conditions).
I also prefer it since you can jump into the process of the querying meaning you can do actions before the query is commited, after it is commited, apply rules and much more. I haven't seen this in an easy way in CI.
Read the example in the docs to see what I'm talking about.
Integration into CI is painless with Doctrine (there are many posts available on the internet and even some here on SO) so you don't have to learn any fancy new conventions.
Whetever you chose, keep in mind that any ORM will add a massive (compared to what CI's base footprint is) overhead to a very very light-weight framework. So you sacrifice the light-weightness for powerfull database features and more abstraction.

- 12,656
- 3
- 46
- 67
I prefer to use Active Record. It's already there and I have not encountered a situation where it hasn't met my needs. I have not used another ORM on top of CodeIgniter, but I suspect it would add an unnecessary layer in most circumstances.
What do you need to do that the built in Active Record tools do not provide?

- 1,501
- 1
- 9
- 13
-
3Active Record is only a pattern, ORM tools support this pattern, but add much more (like configuration of your tables in your classes). The standard Active Record class of CI only provides you with a basic interface. – thomaux Dec 30 '10 at 13:19
I think you should just use active record because most of the times I think you could pay a big penalty by using another layer of abstraction(ORM).

- 60,935
- 33
- 147
- 186
One option is DataMapper ORM:

- 338
- 1
- 5
-
1That name is misleading, its not a DataMapper pattern its implementing the ActiveRecord pattern. – beberlei Jan 03 '11 at 13:47