• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using methods on objects

#1
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.