class loader
{
private static $loaded = array();
public static function load($object)
{
$valid = array( "library",
Chapter 9
[ 213 ]
"view",
"model",
"helper",
"router",
"config",
"hook",
"cache",
"db");
if (!in_array($object,$valid))
{
$config = self::load("config");
if ("on"==$config->debug)
{
base::backtrace();
}
throw new Exception("Not a valid object '{$object}' to load");
}
if (empty(self::$loaded[$object])){
self::$loaded[$object]= new $object();
}
return self::$loaded[$object];
}
}
?>
Loader uses another config file (core/main/config.php), which actually loads
different configs from under config/configs.php file:
class config
{
private $config;
function __construct()
{
global $configs;
include_once("core/config/configs.php");
include_once("app/config/configs.php");
$this->config = $configs;
}
private function __get($var)
{
return $this->config[$var];
}
}
?>
Building Better with MVC
[ 214 ]
If you wonder how our configs.php will look, here it goes:
$configs['debug']="on";
$configs['base_url']="http://localhost/orchid";
$configs['global_profile']=true;
$configs['allowed_url_chars'] = "/[^A-z0-9\/\^]/";
$configs['default_controller']="welcome";
?>
Well, if you look at the code of loader.
Pages:
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229