SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: setting global include paths
-
Mar 30, 2005, 20:17 #1
- Join Date
- Mar 2003
- Location
- Oakland
- Posts
- 71
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
setting global include paths
I was looking at phpmvc.net and noticed that they do the following:
PHP Code:function getGlobalPaths() {
// Setup the main phpmvc application include() directories here
// Note: could be placed in a n xml config file later !!
$appDirs = array();
$appDirs[] = ''; // application root directory
$appDirs[] = 'WEB-INF';
$appDirs[] = 'WEB-INF/lib/collections';
$appDirs[] = 'WEB-INF/lib/database';
// ... there are about a dozen lines like this
$appDirs[] = 'WEB-INF/classes/phpmvc/upload';
$appDirs[] = 'WEB-INF/classes/phpmvc/utils';
return $appDirs;
}
PHP Code:ini_set('include_path', $cPath);
PHP Code:include 'PressRelase.php';
What I do is set constants like TEMPLATES, CLASSES and then when I need to include a TEMPLATES, I go
PHP Code:include TEMPLATES.'PressRelease.php';
Konky 2000 Collections - Japanese stickers and floaty pens
-
Mar 30, 2005, 20:42 #2
- Join Date
- Aug 2004
- Location
- Canada
- Posts
- 1,280
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by konky2000
On the reseller one, I have an account called global, and, I include all my stuff through it. include("/home/global/class/asdf.php");
On the dedicated one, I do the same thing, but use /usr/phpdev/classes/
However! Neither of these are transferable solutions, if you plan on distributing your projects I find the define() method works the best (your include TEMPLATES."/file";
My initial gut feeling is that this is a bad idea. It seems like a potential performance problem if every single time I include a file, PHP is going to have to search through all those directories until it find the file I'm looking for.GamesLib.com - the slickest, most complete and
easily navigatible flash games site on the web.
-
Mar 30, 2005, 23:08 #3
- Join Date
- Oct 2003
- Location
- The Netherlands
- Posts
- 406
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I use an object with public variables, which get assigned from a config.php file. Using them goes as follows:
PHP Code:require_once $config->site_path . '/lib/class_blah.php';
-
Mar 31, 2005, 00:38 #4
- Join Date
- Apr 2004
- Location
- Melbourne
- Posts
- 362
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
We use something similar in prado (using('path.to.class.folder')
which adds the path/to/class/folder directory to the include path, which is then hit by __autoload. This way only folders that are actually going to be used are added to the classpath instead of having to have it predefined somewhere. There is something of a performance hit, but the ease of just having your classpath instead of worrying about including() files is better.
Bookmarks