Ok - I am having a crack at OO php.
I have created some classes (for example user, item)
Firts of all on my index page I check a login (username, password). If there is a match in the database i get the id from the database and store it in a session. Then i create a new instance of my user class and call a function called "getDetails". I pass the session id to this method which then gets all the users details from the database and sets the user objects parameters - here is an example (the index page)
Code: Select all
require_once 'user_class.php';
$user = new user();
$user->getDetails($_SESSION['id']);
echo $user->firstname; // print users first name
If i create a NEW page (items.php) how do I access my $user object from that page??
Do i have to create a new instance and then hit the database again?? Or is there a way to have an object to be universally available?? it seems a bit stupid to have to instantiate and then populate a new object on every single page?
I am pretty sure this is a dumb question but all the examples i have seen have the object created and used within scope.
I know I can pass an object to a function etc and have tried get and set methods but nothing seems to work
I bascially want to create an object then have it universally available throught the site for the duration of the session....
Any pointers, advice, critisism welcome
Thank you