0

I have a MVC that is structored like this

Modules
-Mod1
  -controller
  -Model
  -View
-Mod2
 -controller
 -Model
 -View

and than I have an autoload function that I need it to load all the files in the directory Model, regardless of what Module it is

// Autoload all models files in all Modules.
function models_autoload($class)
{   $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ',  strtolower($class) )));
    $classFile.='.php';
    $files=LUCID_MODULES.'./model/'.$classFile;
    if(file_exists($files)==FALSE)
    {    
        return FALSE;
    }
    include ($files);
}

spl_autoload_register('models_autoload');

my question is, how do I specify in my auto load function above to look recursively in all the Modules for a Model Directory and include all files in models directories.

Ahmad Khan
  • 529
  • 1
  • 7
  • 24
  • So you want to load model classes from outside of the particular mod being called? Doesn't sound like you have separated your logic very well, or you need to create library of classes common to all mods. – Mike Brant Jun 28 '13 at 23:07
  • No, not from outside. thank you – Ahmad Khan Jun 28 '13 at 23:19

1 Answers1

0

Integrate this function:

http://php.net/manual/en/function.glob.php

It will end up giving you a list of all models in all Module directories that you can just iterate through.

Are they all the same namespace? (Assuming you're using namespaces)

Shane H
  • 3,263
  • 5
  • 26
  • 30