A: 

__autoload is used to auto load class includes.

It means everytime you create a new instance of a class that PHP doesn't know the definition yet, PHP will call the __autoload function and hope to get the class definition included.

I don't see any code creating an object in your code, if you take a look at the PHP of __autoload, they provide this sample.

<?php
function __autoload($class_name) {
    require_once $class_name . '.php';
}

$obj  = new MyClass1();
$obj2 = new MyClass2(); 
?>

If you are looking for including the view when you create the controller object something like this should work, your controller would have to be named like foobarController for this to work properly.

$modulesDir = array (
    ROOT_DIR.'mods/type',

);
$view_name = "admin_view.php";

function __autoload($class_name) {
    global $modulesDir;
    if(preg_match('/(\w+)Controller/', $class_name, $match)){
      $class = $match[1];
      // TODO: include the class definition
      // require CONTROLLER_DIR . $class_name . '.php';
      foreach ($modulesDir as $directory) {
        if (file_exists($directory . strtolower($class) . '_view.php')) {
                require_once ($directory . strtolower($class) . '_view.php');
                return;
        }
      }
    }
}

$adminController = new AdminController();
RageZ
ah, sorry.. no, to clarify, I am just including php view files.. not classes..
revive
yeah but your view are not classes right, so why using `__autoload` ?
RageZ
pure ignorance .... i'm ashamed to say.. :(
revive
@Jesse: not a prob everybody learns!
RageZ
;) thanks RageZ... !
revive
+1  A: 

Not sure if that's the only issue in your code, but check this out:

$modulesDir = array (
    ROOT_DIR.'mods/type',
);

if (file_exists($directory . $view_name)) { ... }

You're not ending your folder names in the $modulesDir with a /

When you do file_exists($directory . $view_name), you're actually checking for a file named

ROOT_DIR.'mods/typeadmin_view.php'

and not what you wanted

ROOT_DIR.'mods/type/admin_view.php'

Edit:

Regarding the use of __autoload($name), one thing to keep in mind is:

From PHP Documentation: Autoloading Classes:

You may define an __autoload function which is automatically called in case you are trying to use a class/interface which hasn't been defined yet.

It means that if you're not using classes or if the classes you're using are already 'included', it won't be called.

From your question, it wasn't clear at first glance if you were using classes or not, even tho it looked like your use of __autoload() wasn't appropriate.

One way or the other, your approach of using glob("/path/*/file.php") seems good.
It is simple, clear and gets the job done.
Unless you find an specific problem with it, you should be good to go.

Carlos Lima
excellent.. thank you for the catch!
revive
If he answered your question, click the check mark so he gets credit for it!
iddqd
it was definitely a correction that was needed,. however from what I'm reading, I should be using something other than __autoload to load specific php files into another... but the catch is greatly appreciated!
revive
Feel free to 'accept' the answer that you feel solved your problem (or no answer at all if you think none of them did it). But as a general rule, give upvotes to all the answers you felt were helpful. You should give upvotes not only on your questions but anytime you search for a problem and find a helpful answer. That's how the StackOverflow sorts the answers as well as giving credits to those taking the time to help. Anyway, hope you solved your problem! :)
Carlos Lima
@Carlos... I've tried to upvote those that were helpful.. but it says that I need a Reputation of 15 to do so.. :-/ Everyone on here has been very helpful, and I'm grateful for all the feedback.. hopefully soon I'll be able to show it, as my rep goes above 15.
revive
So true. I forgot about that. First time I answered a question here I couldn't even put links on the answer because of reputation limit. :)
Carlos Lima
+1  A: 

You can use the SPL's RecursiveDirectoryIterator to iterate over all files in a directory and its subdirectories.
Then you can use a class extending FilterIterator to limit the result to specific files.

e.g.

<?php
class EndsWithFilterIterator extends FilterIterator {
  protected $s;
  public function __construct($s, $it) {
    parent::__construct($it);
    $this->s = $s;
  }

  public function accept() {
    $c = parent::current();
    return false!==stripos($c, $this->s, strlen($c)-strlen($this->s));
  }
}


$directory = 'type/';
$it = new EndsWithFilterIterator('admin_view.php',
  new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory))
);
foreach($it as $f) {
  echo $f, "\n";
  // require_once $f;
}
VolkerK