Skip to content

Instantly share code, notes, and snippets.

@aloha1003
Created May 12, 2015 09:55
Show Gist options
  • Save aloha1003/6ed1a19ab0c91a0cf45d to your computer and use it in GitHub Desktop.
Save aloha1003/6ed1a19ab0c91a0cf45d to your computer and use it in GitHub Desktop.
CodeIginter Autoload
/*
* Append this to the end of your application/config.php
*/
spl_autoload_extensions('.php'); // Only Autoload PHP Files
spl_autoload_register('my_autoload');
function my_autoload($classname)
{
$autoLoadDirAry = array(
APPPATH . 'libraries/',
APPPATH . 'model/',
APPPATH . 'interface/',
);
// Namespaced Classes
$classfile = (str_replace('\\', '/', $classname));
foreach ($autoLoadDirAry as $key => $dir) {
if ($classname[0] !== '/') {
$classfile = $dir . $classfile . '.php';
if (file_exists($classfile)) {
require($classfile);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment