Skip to content

Instantly share code, notes, and snippets.

@olivermt
Created July 13, 2011 13:55
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 olivermt/1080332 to your computer and use it in GitHub Desktop.
Save olivermt/1080332 to your computer and use it in GitHub Desktop.
//in my config file
require_once(SITE_DIR . '/class/ClassAutoLoader.php');
$loader = new ClassAutoLoader();
//the autoloader
<?php
class ClassAutoloader {
public function __construct() {
spl_autoload_register(array($this, 'loader'));
}
private function loader($className) {
include (SITE_DIR . '/class/' . $className . '.php');
}
}
?>
/*
Usage: one class per file, name file the same as the class, and the autoloader will load it.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment