You can use it every time you load, you automatically load the corresponding classes. You need to change directories, depending on your project. you can echo or print_r print which classes are loaded every time you call something. also, all your class names should have the same format, for example, className.class.php, for example Dashboard.class.php, Category.class.php. You can use ucwords to make first capital letters.
function __autoload($className) { if (file_exists(__DIR__ . '/../library/' . strtolower($className) . '.class.php')) { require_once(__DIR__ . '/../library/' . strtolower($className) . '.class.php'); } else if (file_exists(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php')) { require_once(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php'); } else if (file_exists(__DIR__ . '/../application/models/' . strtolower($className) . '.php')) { require_once(__DIR__ . '/../application/models/' . strtolower($className) . '.php'); } }
source share