Your problem has little to do with MVC and is more about using global variables or global values.
Many of these classes usually require one instance for each class ("single"), and in some cases single games cannot be avoided, and in your case they are fine to have them.
How many books, textbooks, does not teach how, when and where singletones should be initialized. Its changes are from a programming language to a programming language.
And, in the case of websites where the variables lose their value when they go to another page, this becomes complicated.
There is this concept called "session variables" that work with single points, which allows you to save values when moving from one page to another:
http://php.net/manual/en/session.examples.basic.php
Let you have a website. It has several files and several pages. Some of these php files are called directly and are considered "web pages", for example, "index.php".
Other php files are library files and are “required” or “included” by other files and are not considered “web pages” themselves.
When a user clicks a link on a wbe page and the browser calls up another web page, other values may be lost. This is not like opening another form in a desktop application.
Think about it when a user first appears on a website (example: “index.php”): the main file “includes” or “requires” other files and initializes global variables or single packages:
<?php // filename: "config.php" // another includes or requires here class Config { // begin data section public static $UserName; public static $UserPassword; // end data section // begin singleton section private static $_instance; public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self; } return self::$_instance; } // end singleton section // start session section public static function SaveSession() { $_SESSION['config_username'] = Config::$UserName; $_SESSION['config_password'] = Config::$UserPassword; } public static function RestoreSession() { Config::$UserName = $_SESSION['config_username']; Config::$UserPassword = $_SESSION['config_password']; } // end session section } // class Config ?> <?php // filename: "index.php" include ("config.php"); // another includes or requires here class Application { public static function main() { // prepare session variables session_start(); // prepare singletons here $instance = Config::getInstance(); // this code its an example $instance->UserName = "johndoe"; $instance->UserPassword = "123"; $instance->SaveSession(); // all the page construction goes here // ... } } // // program starts here: Application::main(); ?>
When the user navigates to another page, the application must reload the session data into singletones.
<?php // filename: "customers.php" include ("config.php"); // another includes or requires here class Application { public static function main() { // copy data from session to singletons $instance->RestoreSession(); // all the page construction goes here // ... } } // // program starts here: Application::main(); ?>
Odinal is not related, usually they are independent values.
Greetings.