SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php autoload across multiple dirs?

    Hi all,

    I'm trying to use php's autoload function to dynamically include class files, but the class files are all over the filesystem, not in just one directory (for example, I have folders called 'lib', 'util', 'modules' etc..) - the class file may be under any one of these directories.

    I could hardcode the directories into autoload() but what if the directory structure changes? Is there a way to extend autoload to check several directories without hardcoding?

    Can anyone help?

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    If your classes are under one main directory you can try to recursively check each subdirectory until it finds it. Otherwise hardcoding is your only option that I know of.

  3. #3
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stymiee View Post
    If your classes are under one main directory you can try to recursively check each subdirectory until it finds it. Otherwise hardcoding is your only option that I know of.
    Yeah, I'm traversing the whole directory tree.. using a static variable to hold the list of paths to the class files so I'd only need to run the traversal once. Seems to work fine for now..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •