I figured it might be interesting to explain my entire config file/include file method. One of the reasons I've settled on this method is for ease of moving between a development server and a production server.
1. I have a repository directory (as already outlined in the article). The initialize.php script is for use with this repository code.
2. I use 2 configuration files for site specific stuff. These are stored in the conf directory of the repository.
a) File one i call sitename.base.conf.php and it contains the call to inlcude the intializaton script as well as server (production vs dev) specific base paths and urls. I actually have 2 versions of this file which i dont change once created becaue they only contain 3 pieces of information. One is for the dev server and one is for production server.
b) The second file is called sitename.conf.php and it first calls sitename.base.conf.php and then it defines constants specific to the site classes, directories, templates etc. Once i start developing the site I only alter this file so I can copy it to both servers w/o making server specific changes (base paths or urls).
3. I call only sitename.conf.php from all pages in the site. Because this file is in the repository/conf folder I can still just use include_once('sitename.conf.php');
So for a dev server I have:
initialize.base.php
initialize.php
-sitename.base.conf.php
-sitename.conf.php
The base files are dev/production specific and dont change. I make changes in the conf and initialize files because they are the portable files.
example intialize.base.php:
PHP Code:
$reposPath = "/Library/Apache2/repository";
example initialize.php
PHP Code:
include_once('initialize.base.php');
$LIB_DIR = $reposPath.'/libraries/';
define('DB', $LIB_DIR.'database/database.class.php');
define('SESSION', $LIB_DIR.'session/session.class.php');
example sitename.base.conf.php
PHP Code:
define('BASE_DIR', '/Library/Apache2/htdocs/sitename/');
define('BASE_URL', 'http://sitename/');
define('LIB', BASE_DIR.'lib/');
example sitename.conf.php
PHP Code:
include_once('initialize.php');
include_once('sitename.base.conf.php');
define('SITE_USERS', LIB.'model/users.class.php');
define('TABLEDAO', LIB.'dao/tableDAO.class.php');
And finally in any given page:
PHP Code:
include_once('sitename.conf.php');
include_once(DB);
include_ocne(SITE_USERS);
//blah blah do something clever with all those wonderful classes
HTH someone
Bookmarks