Reputation: 5427
There's a magic function to autoload classes (__autoload), I want to know if there a way to load a file without a class.
Something like this:
require ('example_file'); // Trigger __autoloadfiles function
function __autoloadfiles($filename)
{
$files = array(
ROOT . DS . 'library' . DS . $filename. '.php',
ROOT . DS . 'application' . DS . $filename . '.php',
ROOT . DS . 'application/otherfolder' . DS . $filename. '.php'
);
$file_exists = FALSE;
foreach($files as $file) {
if( file_exists( $file ) ) {
require_once $file;
$file_exists = TRUE;
break;
}
}
if(!$file_exists)
die("File not found.");
}
Upvotes: 0
Views: 619
Reputation: 8990
You can define own function for requiring:
function require_file($file) {
// your code
}
and then call it
require_file('file');
I guess that there is no way to overload require
function.
Upvotes: 1