note 102394 modified in language.oop5.autoload by danbrown
[email protected] Fri, 11 Feb 2011 08:14:33 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
This is an example of how I used autoloading in my application:
<?php
spl_autoload_register(function ($className) {
$possibilities = array(
APPLICATION_PATH.'beans'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'controllers'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'libraries'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'models'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'views'.DIRECTORY_SEPARATOR.$className.'.php',
$className.'.php'
);
foreach ($possibilities as $file) {
if (file_exists($file)) {
require_once($file);
return true;
}
}
return false;
});
?>
--was--
This is an example of how I used autoloading in my application:
<?php
spl_autoload_register(function ($className) {
$possibilities = array(
APPLICATION_PATH.'beans'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'controllers'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'libraries'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'models'.DIRECTORY_SEPARATOR.$className.'.php',
APPLICATION_PATH.'views'.DIRECTORY_SEPARATOR.$className.'.php',
$className.'.php'
);
foreach ($possibilities as $file) {
if (file_exists($file)) {
require_once($file);
return true;
}
}
return false;
});
?>
http://www.lystadonline.no/
http://php.net/manual/en/language.oop5.autoload.php