Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.