Liquid Fire Posted August 15, 2007 Share Posted August 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65075-auto-load-question/ Share on other sites More sharing options...
trq Posted August 15, 2007 Share Posted August 15, 2007 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65075-auto-load-question/#findComment-324800 Share on other sites More sharing options...
Liquid Fire Posted August 18, 2007 Author Share Posted August 18, 2007 That seems to work, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/65075-auto-load-question/#findComment-327327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.