Witam,
mam kod classloadera:
<?php
function classLoader($class_name)
{
$class_file = $_SERVER['DOCUMENT_ROOT'] . '/test/inc/classes/' . $class_name . '.php';
{
require_once($class_file);
}
else
{
throw new Exception('Class "' . $class_name . '" cannot be found.');
}
}
spl_autoload_extensions('.php');
spl_autoload_register('classLoader');
function functionLoader($function_name)
{
$function_file = $_SERVER['DOCUMENT_ROOT'] . '/test/inc/functions/' . $function_name . '.php';
{
require_once($function_file);
}
else
{
throw new Exception('Function " ' . $function_name . ' "cannot be found.');
}
}
spl_autoload_extensions('.php');
spl_autoload_register('functionLoader');
?>
I teraz dołączam go tak:
include($_SERVER['DOCUMENT_ROOT'] . '/test/inc/functions/functions_loader.php');
functionLoader('functions');
Dobrze robię, jeśli mam nazwe klasy np:
$db = new Db_Pdo()
to nie muszę robić
classLoader('db_pdo');
, i zastanawiam, się czy to:
spl_autoload_extensions('.php');
spl_autoload_register('functionLoader');
jest potrzebne
Ten post edytował julek12 22.11.2009, 07:44:26