[thelist] Unsubcribe
Garrett Coakley
garrett at polytechnic.co.uk
Thu Jan 31 12:15:01 CST 2002
On Thu, 31 Jan 2002 09:25:07 -0800
Howard Cheng <howcheng at ix.netcom.com> wrote:
> Here's how to unsubscribe:
[snip]
As funny as that was.... you owe a tip *:)
G.
<tip type="Programming Tip" author="Garrett Coakley">
When you're building an app in PHP[1] that involves a number of files
which all need access to some core variables, then why not stick them in
a master config file and include that file where needed. Even better,
stick them in an array and keep your global namespace tidy.
As an example, have a look at how the Geeklog project does it:
[garrett at cincinnati ~]$ more config.php
$_CONF['path'] = '/var/www/polytechnic/';
$_CONF['path_system'] = $_CONF['path'] . 'system/';
$_CONF['path_html'] = $_CONF['path'] . 'public/';
$_CONF['path_log'] = $_CONF['path'] . 'logs/';
$_CONF['path_language'] = $_CONF['path'] . 'language/';
$_CONF['rdf_file'] = $_CONF['path_html'] . 'backend/geeklog.rdf'
Here you can see that they have set up an associative array called
$_CONF which contains entries for all the major configuration switches.
This file gets called in each page with:
include_once('/var/www/polytechnic/config.php');
and the variables are accessed by referring to $_CONF['keyname'].
Once benefit of this is the portability of the code. If you need to move
your site to another server with a slightly different file system, lets
say it keeps web files in /home/httpd instead of /var/www as I have
above, then all you need to do is change the entry in the config file
for $_CONF['path'] and away you go.
[1] Just as an example because it's what I work with, Perl/CF/ASP etc
all have similar methods that you can use.
</tip>
--
-----------------------------------------------------------------------
WORK: http://spiked.co.uk/
PLAY: http://polytechnic.co.uk/
More information about the thelist
mailing list