Hi there,
I'm interested in knowing how people are __autoload'ing from several different folders. Do you have a class that caches the paths of the files, or do you perhaps do something like database_mysql where _ gets replaced by / and then it becomes database/mysql.php ? or do you setup a static variable or an ini file or ... ? So what is the way you tell your autoload where certain classes are located?
Best way of __autoload'ing from several folders?
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Best way of __autoload'ing from several folders?
Typically you would append your library path to the include path using set_include_path(). Then, depending on the naming conventions, you would parse the class name to determine it's filepath. The most common would be http://framework.zend.com/manual/en/cod ... tions.html where underscores are converted to classes. I.e.
would look for foobar/database/mysql.php relative to your include path.
Code: Select all
$foo = new Foobar_Database_Mysql();- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Best way of __autoload'ing from several folders?
Yea that's what I was first going to do.. It's just that the classnames have to be then foobar_database_mysqlJcart wrote:Typically you would append your library path to the include path using set_include_path(). Then, depending on the naming conventions, you would parse the class name to determine it's filepath. The most common would be http://framework.zend.com/manual/en/cod ... tions.html where underscores are converted to classes. I.e.
would look for foobar/database/mysql.php relative to your include path.Code: Select all
$foo = new Foobar_Database_Mysql();