Welcome Guest, Not a member yet? Register   Sign In
sub-models? Getting objects out of database
#1

[eluser]alexmiller[/eluser]
I am slowly getting to grips with CI.

I have a model for people. It has fields for first_name, last_name etc. So I have set up person_model as a CI model eg. (pseudo-code)

Code:
class person_model extends Model
{
    function getPersonById($id)
    {
        $Q = $this->db->get_where('people',array ('user_id'=>$id),1);
        return $Q->row();
    }
}
I can then call this in my controller:

Code:
$person = $this->person_model->getPersonById(1);
But here's the question:
I want to be able to do things like:
Code:
echo $person->possessive(); // adds 's to end of first_name
echo $person->full_name(); // concats first_name and last_name

I know I can get an object out of my database result, but how can I add methods to that object? More importantly, am I circumventing the MVC structure here? In a way, I am creating another model layer.


Messages In This Thread
sub-models? Getting objects out of database - by El Forum - 09-17-2008, 04:30 AM
sub-models? Getting objects out of database - by El Forum - 09-17-2008, 05:01 AM
sub-models? Getting objects out of database - by El Forum - 09-17-2008, 05:06 AM
sub-models? Getting objects out of database - by El Forum - 09-17-2008, 05:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB