jcadima
4/18/2016 - 1:22 AM

SPL Auto Register Multiple Directories - No Namespaces

SPL Auto Register Multiple Directories - No Namespaces

<?php
http://stackoverflow.com/questions/7713072/how-can-i-load-classes-from-multiple-directories-with-autoload


/*  DIRECTORY EXAMPLE:
controllers/Home.php
controllers/Shares.php

models/Home_Model.php
models/Share_Model.php

classes/Loader.php
classes/Controller.php

*/

function autoload_class_multiple_directory($class) 
{
echo $class . '<br>';
    # List all the class directories in the array.
    $array_paths = array(
        'classes/', 
        'controllers/',
        'models/'
    );

    foreach($array_paths as $path)
    {
        $file =    $path . $class   . '.php' ;
        if(is_file($file)) 
        {
            require $file;
        } 

    }
}

spl_autoload_register('autoload_class_multiple_directory');