CodeIgniter Forums
Using methods on objects - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using methods on objects (/showthread.php?tid=22343)



Using methods on objects - El Forum - 09-05-2009

[eluser]bapobap[/eluser]
Would someone kindly explain how the following works as I'm not sure what is going on code wise.

So for this:
Code:
$user = $this->db->limit(1)->get('users');

It returns:
Code:
CI_DB_mysql_result Object
(
    [conn_id] => Resource id #32
    [result_id] => Resource id #54
    [result_array] => Array
        (
        )

    [result_object] => Array
        (
        )

    [current_row] => 0
    [num_rows] => 1
    [row_data] =>
)

from there you can do things like:
Code:
$user->row(); or $user->result();

What is actually happening here? I'm more used to having a user model where I get the user object, then pass it back into methods, so:
Code:
$user = $this->user_model->user('username');
$email = $this->user_model->email($user);

whereas something like:

Code:
$user = $this->user_model->user('username');
$email = $user->email();

is much handier.

Though I may be misunderstanding how all this is working.