I have a class called Layout for the page layout, another class called User for the user.
Each page I create creates a new layout.
When a user logs in, a new user is created.
How do I get an instance of a layout class to find out about an instantiated user? I could also save the entire user instance in a session variable. I guess this is a bad idea. What are the best methods for doing this?
class User { var $userid; var $email; var $username; function User($user) { $this->userid = $this->getUid($user); $this->email = $this->getEmail($user); $this->username = $user; } function getUid($u) { ... } function getEmail($u) { ... } } class Layout { var $var1; var $var2; var $var3; function Layout() {
so in index.php, for example, I would do the following:
include "user.php" include "layout.php" $homelayout = new Layout(); $homelayout->function1(); $homelayout->function2(); $homelayout->function3();
now say that in login.php someone is logged in:
include "layout.php" include "user.php" if(userAuthSuccess) { $currentUser = new User($_POST['username']); }
What is the best way to access $ currentUser and its member variables like $ currentUser-> email, etc. from all php files from here if the user has not logged out?
source share