• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Confusion!

#1
[eluser]seminalJim[/eluser]
Hi guys, I've been using Codeigniter for few months now and doing PHP for not much longer... I'm confused about how to do something with a library I'm making for my users. I need to create two objects, one for the current user and another for the users profile that the current user is viewing.

I have a class for users, eg

Code:
class User
{
public display_name;
public dob;
...(etc)
public function load( $uid )
{
   // Get User From DB
   return $this
}
}

and i'd like to load the users in my controller with...

Code:
$current_user = $this->user->load( $current_user_id );
$other_user = $this->user->load( $other_user_id );

But, when I check the current user and the other user they are the same? So i guess this is because the class is not being copied, but is being passed by reference or something?

All i want is to be able to pass these to my views and access them like:
Code:
Me: <?PHP $current_user->display_name ?>
Other: <?PHP $other_user->display_name ?>

Is this possible, or am completely on the wrong track?

#2
[eluser]Aken[/eluser]
You can't return $this -- you'd need to create a new instantiation and return that.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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