__autoload
is used to auto load class includes.
It means everytime you create a new instance of a class that PHP doesn't know the definition yet, PHP will call the __autoload
function and hope to get the class definition included.
I don't see any code creating an object in your code, if you take a look at the PHP of __autoload
, they provide this sample.
<?php
function __autoload($class_name) {
require_once $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
?>
If you are looking for including the view when you create the controller object something like this should work, your controller would have to be named like foobarController
for this to work properly.
$modulesDir = array (
ROOT_DIR.'mods/type',
);
$view_name = "admin_view.php";
function __autoload($class_name) {
global $modulesDir;
if(preg_match('/(\w+)Controller/', $class_name, $match)){
$class = $match[1];
// TODO: include the class definition
// require CONTROLLER_DIR . $class_name . '.php';
foreach ($modulesDir as $directory) {
if (file_exists($directory . strtolower($class) . '_view.php')) {
require_once ($directory . strtolower($class) . '_view.php');
return;
}
}
}
}
$adminController = new AdminController();