Skip to content

Instantly share code, notes, and snippets.

@frosenlind
Forked from JunaidQadirB/config.php
Created January 23, 2016 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosenlind/bc7f254fd0e9d1b4be20 to your computer and use it in GitHub Desktop.
Save frosenlind/bc7f254fd0e9d1b4be20 to your computer and use it in GitHub Desktop.
Enable Class loading with Namespaces in CodeIgniter
/*
* Append this to the end of your application/config.php
* @see http://stackoverflow.com/questions/3700626/namespace-in-php-codeigniter-framework#21858556
*/
spl_autoload_extensions('.php'); // Only Autoload PHP Files
spl_autoload_register(function($classname) {
if (strpos($classname, '\\') !== false) {
// Namespaced Classes
$classfile = (str_replace('\\', '/', $classname));
if ($classname[0] !== '/') {
$classfile = APPPATH . 'libraries/' . $classfile . '.php';
}
require($classfile);
} else if (strpos($classname, 'interface') !== false) {
// Interfaces
strtolower($classname);
require('application/interfaces/' . $classname . '.php');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment