Data mapper with MVC

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Data mapper with MVC

Post by Luke »

I have come to the decision to use Data Mapper instead of Active Record. My question is regarding using Data mappers within a Model-View-Controller architecture. Those of you who have built a system like this... how was it structured? Here's what came to mind for me:

I would have two main abstract classes: Mysql_DataMapper, Mysql_DataModel. For each model, I would override both of these classes... each Mysql_DataModel object would use it's corresponding Mysql_DataMapper object to know how to store itself in the database... does this sound about right? Does anybody have any code example for a data-mapper type solution? Thanks a lot guys!
User avatar
johno
Forum Commoner
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia
Contact:

Post by johno »

Look at Torpedeo in my signature ;-)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Can you only download source if you have subversion on google code??
User avatar
johno
Forum Commoner
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia
Contact:

Post by johno »

The Ninja Space Goat wrote:Can you only download source if you have subversion on google code??
I don't clearly understand what you mean. Do you want to download source code? You have to use svn checkout or svn export.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

That's what I mean... seems stupid to force users to use SVN just to download source... sourceforge lets you download zipped packages and stuff... ??
User avatar
johno
Forum Commoner
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia
Contact:

Post by johno »

The Ninja Space Goat wrote:That's what I mean... seems stupid to force users to use SVN just to download source... sourceforge lets you download zipped packages and stuff... ??
SVN/CVS version control is essential stuff so developers should be using it anyway ;-) Ok seriously, the reason is that Torpedeo is in early development stage so I don't really cared about that. Sourceforge is of course better, but more complicated. I wanted it to be simple.

Anyways this is offtopic. If you want to know how it works. Look at ClassMapping which is composed of FieldMappings.
http://torpedeo.googlecode.com/svn/trun ... apping.php
http://torpedeo.googlecode.com/svn/trun ... apping.php

ClassMappings knows how to map rows from sql select to class. It maps row to transfer object (mapRowToTransfer() method).

That's for a good start.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

To respond to the original post, I don't think the Mapper should be extended to create the model. I believe a Mapper is more like a Connection class in that it does not contain business logic -- unlike Active Record which can. I think these days they add a lightweight O/R Mapper to the Active Record (ala Rails) when they want business logic included.
(#10850)
Post Reply