When designing the directory structure of your application, consider a portable
one. A portable directory structure is one that is easy to deploy and avoids hardcoded
fully qualified paths whenever possible.
%DocumentRoot%
|
+---app_name
|
+--apps
|
+---class
|
+---templates
%DocumentRoot%
|
+---framework
|
+---pear
|
+---phplib
|
+---calendar
|
+--apps
|
+---class
|
+---templates
This directory structure can be created using the following PHP code
// If you have installed PEAR packages in a different
// directory than %DocumentRoot%/pear change the setting below.
$PEAR_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/pear’ ;
// If you have installed PHPLIB in a different
// directory than %DocumentRoot%/phplib, change the setting below.
$PHPLIB_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/phplib’;
// If you have installed framewirk directory in a different
// directory than %DocumentRoot%/framework, change the setting below.
$APP_FRAMEWORK_DIR = $_SERVER[‘DOCUMENT_ROOT’] . ‘/framework’;
//If you have installed this application in a different
// directory than %DocumentRoot%, chance the settings below.
$ROOT_PATH = $_SERVER[‘DOCUMENT_ROOT’];
$REL_ROOT_PATH = ‘/calendar’;
$REL_APP_PATH = $REL_ROOT_PATH . ‘/apps’;
$TEMPLATE_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/templates’;
$CLASS_DIR = $ROOT_PATH . $REL_APP_PATH . ‘/class’;
$REL_TEMPLATE_DIR = $REL_APP_PATH . ‘/templates/’;
The key point is that you should avoid hard-coding a fully qualified path in the
application so that deployment of your application is as hassle-free as it can be. For
example, say you have developed the application on your Web server with the following
directory structure:
/usr/local/apache/htdocs
|
+---your_app
|
+---templates
If /usr/local/apache/htdocs is your Web server’s document root
(%DocumentRoot%), make sure that you haven’t hard-coded it in the configuration.
If you use $TEMPLATE_DIR to point to your template directory in your_app.conf,
you should use the following:
$ROOT_PATH = $_SERVER[‘DOCUMENT_ROOT’];
$REL_ROOT_PATH = ‘/your_app;
$TEMPLATE_DIR = $ROOT_PATH . ‘/templates’;
Instead of:
$TEMPLATE_DIR =
‘/usr/local/apache/htdocs/your_app/templates’;
The benefit of the non-hard-coded version is that if you created a tar ball or a
zip file of your entire application and gave it to another user whose Web document
root is set to something else, she doesn’t have to change your application configuration
for fixing paths as long as she installs the application in the
%DocumentRoot%/your_appsee directory.
0 comments:
Post a Comment