I know I need to use spl_autoload_register with Smarty 3. I am registering my autoload function after smarty initializes. But smarty is trying to use my own autoload function instead of the smartyAutoload defined function. Causing an error because it obviously cant find the smarty files using my autoload. Here is the code with everything else cut out to show how it is layed out currently.
I’m sure it is just an order placement issue or something.
<?php
class application {
// include smarty
require_once(SMARTY_DIR.'Smarty.class.php');
// init controller class which initializes smarty
$controller = new Controller();
}
function autoLoader($class) {
// determine what type class it is and call from that directory
$dir = strtolower(strstr($class, '_', true));
$name = substr( strtolower( strstr($class, '_') ), 1 );
switch($dir) {
case 'component':
break;
default:
require_once(LIB_PATH.DS.$name.'.class.php');
break;
}
}
spl_autoload_register("autoLoader");
?>
You can make your autoloader compatbile (that’s what
spl_autoload_registeris actually for) by only require a file if it’s one of your classes.You can do this by checking the class name against a namespace or a whitelist or with
is_file(store the whitelist in the file-system):