Siendo que los ejemplos no usan un objeto para definir la función __autoload, tampoco lo hago yo. Acabo de escribir un archivo config con autoload que funciona.
Código PHP :
<?php
$classes;
defineConstants();
searchClasses( APP_LOCAL_PATH );
function defineConstants(){
/*** ABSOLUTE REMOTE PATH **********************/
// If moving to another server, we must update this!
if (strpos($_SERVER["HTTP_HOST"], "localhost") !== false){
define('APP', 'http://localhost/AoI/AoITutorials/web/../application/');
define('WEB', 'http://localhost/AoI/AoITutorials/web/'); // localhost for development
}
else {
define('APP', 'http://www.artofillusion.com.ar/application/');
define('WEB', 'http://www.artofillusion.com.ar/AoITutorials/');
}
// fix for domain and subdomain issue: aoi-castellano / artofillusion.com.ar
if (strpos($_SERVER["HTTP_HOST"], "castellano") !== false){
header("Location: ".WEB); // redirect.
};
/*** LOCAL PATH **********************/
define('WEB_LOCAL_PATH', dirname(__FILE__)."/../web/");
define('APP_LOCAL_PATH', dirname(__FILE__)."/");
define('APP_LIB', APP_LOCAL_PATH.'Library/');
// html <head> related constants (absolute path)
define('LIBRARY_DIR', 'Library/');
define('LINK_CSS', 'Library/styles/');
define('IMG_DIR', 'Library/images/');
// html <body> related constants (for including ui images, etc)
define('CONTROLLERS', APP_LOCAL_PATH.'controllers/');
define('TEMPLATES', APP_LOCAL_PATH.'templates/');
define('LIBRARY', WEB_LOCAL_PATH.'Library/');
define('CSS_DIR', LIBRARY.'styles/');
}
function __autoload($class){
global $classes;
if (array_key_exists($class.".php", $classes))
require_once $classes[$class.".php"];
}
function searchClasses($dir){
global $classes;
$puntos = array('.', '..');
$list = array_diff(scandir($dir), $puntos);
foreach ($list as $item)
{
if (is_file($dir.$item) and (strpos($item,".php") !== false))
$classes[$item] = realpath($dir)."\\".$item;
elseif (is_dir($dir.$item) and ($item != "Library") and ($item != "templates"))
searchClasses($dir.$item."/");
}
}
?>