Im building a MVC PHP framework and am having some issues with autoloading my classes, which i think might be down to my file structure.
Firstly, here is my file structure:
Im testing developing in an Xampp localserver environment so this is why i have the private and public folders. Eventually on a live server the private folders will be in the server root and the public folders will be in the public_html directory.
Does my file structure look about right? in the private, frontend folder ill have all my different modules in directorys which inturn has a controller, model, view files which hold the neccessary files for each module.
I have created this autoloader so far:
//Require config and router classes
require_once('router.class.php');
require_once('config.php');
spl_autoload_register(null, false);
spl_autoload_extensions('.class.php');
function autoloader_core($class){
$filename = strtolower($class) . '.class.php';
if(!file_exists($filename)){
echo $filename . " not found";
}
include $filename;
}
function autoloader_app($class){
$filename = strtolower($class) . '.class.php';
$file = 'C:\xampp\htdocs\simplebids\simplebidsprivate\app/' . $filename;
if(!file_exists($file)){
echo $file . " not found";
}
include $file;
}
spl_autoload_register('autoloader_core');
spl_autoload_register('autoloader_app');
$router = new test;
$router->say_hello();
This works perfect for the classes within the lib->core directory, but when i try to instantiate a new test class i get all sorts of errors about not finding the test.class.php file in the lib->core file, which it obviously isn't but i thought the autoloader function would be looking in the path defined by myself in the "autoloader_app" function.
The funny thing is even though i get all these errors, the string i echo in the test function say_hello() does get echoed after the errors.
So in short the file isnt being found according to the errors, but it is because i can see the echo i made the classes function print.
Any ideas why?
Also my frontend module file structure, is this going to make autoloading very difficult as ill need a different autoloading function for every module and then every controller/model/view file in it? will i need a seperate autoloading function for every module? If not how would i go about it?
Thanks Tom