Welcome Guest, Not a member yet? Register   Sign In
Iterate a model's attributes within the model?
#17

[eluser]peterphp[/eluser]
I found this code on another forum, it seems to solve the problem by excluding "_parent_name":

Code:
function get()
{
    foreach(get_class_vars(get_class($this)) as $key=>$value)
    {
        if($key != "_parent_name")
        {
            $val = $this->$key;
            if($val) $this->db->where($key, $val);
        }
    }
    // some more code here...
    }
}

Found this snipplet here.

Seems to me like the 'right' way to do it :-)


Messages In This Thread
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 09:01 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 09:12 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 09:27 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 09:41 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 10:17 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 10:30 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 10:36 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 10:40 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 10:44 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 11:05 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 11:36 AM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 01:32 PM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 01:32 PM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 01:44 PM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 02:08 PM
Iterate a model's attributes within the model? - by El Forum - 05-09-2009, 02:09 PM
Iterate a model's attributes within the model? - by El Forum - 12-14-2009, 06:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB