Created
January 28, 2011 21:42
-
-
Save f/801035 to your computer and use it in GitHub Desktop.
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
<?php | |
class autoloader { | |
public static $loader; | |
public static function init() | |
{ | |
if (self::$loader == NULL) | |
self::$loader = new self(); | |
return self::$loader; | |
} | |
public function __construct() | |
{ | |
spl_autoload_register(array($this,'model')); | |
spl_autoload_register(array($this,'helper')); | |
spl_autoload_register(array($this,'controller')); | |
spl_autoload_register(array($this,'library')); | |
} | |
public function library($class) | |
{ | |
set_include_path(get_include_path().PATH_SEPARATOR.'/lib/'); | |
spl_autoload_extensions('.library.php'); | |
spl_autoload($class); | |
} | |
public function controller($class) | |
{ | |
$class = preg_replace('/_controller$/ui','',$class); | |
set_include_path(get_include_path().PATH_SEPARATOR.'/controller/'); | |
spl_autoload_extensions('.controller.php'); | |
spl_autoload($class); | |
} | |
public function model($class) | |
{ | |
$class = preg_replace('/_model$/ui','',$class); | |
set_include_path(get_include_path().PATH_SEPARATOR.'/model/'); | |
spl_autoload_extensions('.model.php'); | |
spl_autoload($class); | |
} | |
public function helper($class) | |
{ | |
$class = preg_replace('/_helper$/ui','',$class); | |
set_include_path(get_include_path().PATH_SEPARATOR.'/helper/'); | |
spl_autoload_extensions('.helper.php'); | |
spl_autoload($class); | |
} | |
} | |
//call | |
autoloader::init(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment