Jump to content

auto load question


Liquid Fire

Recommended Posts

I am tring to figure out how to do something.  I am starting to build a collection of coomon used php class, kind of a framework but not really, that i will be using for all my site.  For instance i have a database class that handle all mysql database stuff.  I have a site class that handles html stuff(generating header/footer, form elements, etc.., know currently i just have all these classes included in 1 folder but it is starting get big and i would like  to be able to start searating them with folders.  the problem is how can i tell the auto load where the class is without changing the name of the class?

Link to comment
https://forums.phpfreaks.com/topic/65075-auto-load-question/
Share on other sites

Something like (not tested)...

 

<?php

  function __autoload($class) {
    if ($handle = opendir('/path/to/includes')) {
      while (false !== ($dir = readdir($handle))) {
        if (is_dir('/path/to/includes/' . $dir) {
          if (file_exists('/path/to/includes/' . $dir . '/' . $class . '.php';
            require_once '/path/to/includes/' . $dir . '/' . $class . '.php';
          }
        }
      }
      closedir($handle);
    }
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/65075-auto-load-question/#findComment-324800
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.