tags:

views:

524

answers:

1

Hi Folks,

does someone knows some good examples for an PHP Application using those 4 "Layers"

ServiceLayer -> Model --> DataMapper --> DAO

Iam not sure if it makes sense, when i use such a design i have to do the following to create a new Record in my Database :

$servcie = new Service(new Mapper(new Dao));
$service->save($data)

the Service is creating an new Data Object and passing it into the Mapper, the Mapper is passing the Data to the provided Dao..

what is the intension to use such constructs ?

Why not simply :

$model = new Model();
$model->save($data)

Model is saving to DB

+2  A: 

Ideally the model should have nothing to do with how it is stored or managed. It should be a pure and portable representation of data (ideally, altho often not so in practice). The controller (or a dedicated sub-controller) should be the one handling this functionality for the model.

Lior Cohen