tags:

views:

28

answers:

1

In one of my new codeigniter project, one of my colleague wrote a helper method array_to_object so that he can call the variables in views as $row->field instead of $row['field'].

I thought codeigniter default behaviour allows us to retrieve data from database in $row->field (as object). Can anyone pls enlight me data flow in codeigniter?

+2  A: 

Codeigniter supports both an array and an object oriented style to retrieve data from DB so both of these styles are equal(from the user guide):

oop style

$query = $this->db->query('SELECT name, title, email FROM my_table');

foreach ($query->result() as $row)
{
    echo $row->title;
    echo $row->name;
    echo $row->email;
}

array style

$query = $this->db->query('SELECT name, title, email FROM my_table');

foreach ($query->result_array() as $row)
{
    echo $row['title'];
    echo $row['name'];
    echo $row['email'];
}

here is the user guide: http://codeigniter.com/user_guide/database/examples.html

rabidmachine9