I'm working on a PHP MVC but struggling to handle certain aspects of the design, making the User information accessible easily to everything is really puzzling me.
I did have User as an abstract class so you could just use User::getUserId() but I'm not sure that was the right way to do it?
I've now changed it to the following but it's not working.
The Problem
Say I have a basic controller where I want to instantiate the User class every time it's run:
Controller
class controller{
    public $user;
    function __construct(){
        $this->user = new User();
        $user->sessionRefresh();
        $user->getUserId();
    }
}
and then I have a User model class that was instantiated:
User Model Class
class User{
    var $userId;
    function sessionRefresh(){
        if (isset($_SESSION['userId']) && $_SESSION['created'] + 15 * 60 < time())                  
            session_regenerate_id();
    }
    function getUserId(){
        $this->userId = $_SESSION['userId'];
    }
}
and then I have more controllers that extend the default controller:
Forum Controller - Very basic just to demo what I'm trying
class forumcontroller extends controller{
    function __construct(){
        require 'templates/forum.php';
    }
}
Forum Template - Very basic example
<html>
<title>Forum</title>
<body>
    <div>Welcome User: <?=$user->userId;?></div>
</body>
</html>
Is what I'm doing completely wrong?
I've only recently tried to take the leap from procedural to mvc/oop in PHP and clearly it's confusing me still.
 
     
     
    