Does someone know some good examples for an PHP Application using following 4 "Layers"
ServiceLayer --> Model --> DataMapper --> DAO
I am not sure if it makes sense but 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 a new Data Object and passing it into the Mapper, the Mapper is passing the Data to the provided Dao..
what is the intention to use such constructs ?
Why not simply :
$model = new Model();
$model->save($data)
Model is saving to DB.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With