views:

33

answers:

0

I usually use a php class to create value objects for my database objects. Something like:

class UserVO 
{
    public $id;
    public $email;
} 

and I then return this as follows:

$data = mysql_query($sql);
while ($row = mysql_fetch_object($data, "UserVO"))
{
    $result[] = $row;
}
return $result; 

I’m now trying to get to grips with CI and the ActiveRecord methods.

I realise that I could do something like the following, buts its a bit more clunky, especially with queries that contain a lot of fields.

foreach ($query->result_array() as $row)
{
    $result[$i] = new UserVO();
    $result[$i]->id = $row['id'];
    $result[$i]->email = $row['email'];
    $i++;
}
return $result;

So, my question: is there a way to get “class_names” (as per http://php.net/manual/en/function.mysql-fetch-object.php) when returning data using the CI ActiveRecord methods?