Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter models VS Doctrine Models
#1

[eluser]Unknown[/eluser]
Hi there!

I'm reading up quite a few CI tutorials lately, and there is alot of mentions of Doctrine in them. They mostly all use them.

I was wondering, what is the difference between both's models ?

Isn't CI a complete framework with models implementation of its own ? Why using Doctrine also ?

Thanks for the info! Smile
#2

[eluser]WanWizard[/eluser]
In CI's architecture, a Model is simply a class within the MVC design pattern, used to hold the code that manages the data. A Model is queried by the Controller, it in turn accesses data sources and returns results back to the controller. You have to write all this code yourself.

Doctrine (and others, like Datamapper), are Object Relationship Mapper. They provide your application with an object view on your data (for example, 1 table row = 1 object), with support for relationships between those objects. You don't have to write queries any more, the ORM will generate those for you based on a 'natural' way of accessing objects:

Code:
// create a post model object
$post = new Post();

// get all john's posts
$post->where_related('author', 'john')->get();

// get laura's user record
$user = new User();
$user->get_by_name('laura');

// make laura the other of the first post found
$user->save($post);

All your model class needs to contain is a definition of the relations, and optionally things like table name and primary key (which are usually generated, so if you follow the rules they are not needed).

An ORM gives you a large set of standard methods for every model object, but you can add your own so you can extend the functionality on a per-model basis, or add global methods (that can be used on every model). ORM's like Datamapper also provide pre- and post validation (so you don't have to code this logic into your controllers). See the link in my sig for an overview of what Datamapper is capable of.
#3

[eluser]Unknown[/eluser]
I see.

The only other PHP framework I know a bit is CakePHP, and CakePHP handles its models just like Doctrine. I guess it has it's own ORL.

I guess this is done to keep CI lighter, and if you need ORL, use a 3rd party, like Doctrine.
#4

[eluser]WanWizard[/eluser]
Cake indirectly uses the datasource class, but it works a bit more complicated. CI doesn't come with one, it's a lightweight framework (and that's the reason why it's easy to work with, and lightning fast compared with Cake).

Doctrine btw is also quite complex, bulky and not to fast. The latest major release improved things quite a bit, but I'm still not impressed.

I suggest you look at what's out there, work a bit with them, and choose the one you're most comfortable with.




Theme © iAndrew 2016 - Forum software by © MyBB