Tuesday, January 5, 2010

Make objects from model data

When I was learning php classes we made a model object for each type
of data we had. Each model would have crud from another class and then
model specific functions & attributes. For example i would have:

class Person extends Crud {
var $first_name;
var $last_name;

static function getperson{
return Crud::get(people,$sql);
}


function full_name() {
return $this->first_name . ' '. $this->last_name;
}
}
class Crud {
// crud
static function get() { sql stuff; return mysql_rows}
static function delete() {sql stuff; }
}

something like that, but anyways we would instantiate each item
returned from the getallPeople() into a person object and then if i
wanted to get the full name of the person i would just type:

$person = Person::getperson(id); //creates person object
$person->full_name(); // use object function

this made it really easy because if i wanted to add something to the
person all i had to do was change the Person object model. I cant get
this to work with cakephp models. What do i need to do for this to
work or do I not understand cakephp's models & MVC right?

No comments: