Created
May 12, 2015 09:55
-
-
Save aloha1003/6ed1a19ab0c91a0cf45d to your computer and use it in GitHub Desktop.
CodeIginter Autoload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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