[eluser]Josh Giese[/eluser]
I am coming from a coldfusion background into this.
Here is what I am going to be trying trying to do with models:
I break things down into the business object, a service and a gateway
announcement.php
-the business object that maps to an announcement record in the db
example:
id
content
date
author_name
-getter /setter functions
announcement_service.php
has no direct access to the database
calls function in itself and other services
calls functions in the corresponding gateway
announcement_gateway.php
contains all queries to the announcements table including, insert, update, delete
this is all pseudo code, but an example of how it would work:
Code:
------------------------------------------------------
//build a new object
message = new announcement
message->set_content("this is the message");
message->set_author_name("Josh");
message->save(); //calls the gateway from an internal method. gateway would do the insert using this object data
/*********************************************************/
ASrvc= new announcement_service
last10Announcements = ASrvc->getLast10(); //service calls the gateway, gateway returns a query
/*********************************************************/
latestPostID = ASrvc->getLatestAnnouncement(); //service calls gateway, queries for lastest record
//service builds and returnes a new announcement object using data returned from the gateway
latestPost->ASrvc->get_announcement(latestPostID);
//update and save
latestPost->set_content("new content here");
latestPost->save();
Am I off base with this? I think the separation of the business object, service and gateway gives me greater flexibility and maintainability.