Sean Malloy wrote:
Moving to PHP from an ASP backgroun, I always found one thing really
annoying about PHP.

With ASP, you could have a file structure such as:

SYSTEM
|--HTML
|  |--header.asp
|
|--LOGIC
|  |--engine.asp
|
|--core.asp

in default.asp, you would
<!--#include file="system/core.asp"-->
in core.asp, engine.asp would be included as such
<!--#include file="LOGIC/engine.asp"-->
in engine.asp, header.asp would be included as such
<!--#include file="../HTML/header.asp"-->


Its a bad example. However, it demonstrates that the relative path for each
include changed depending on what file was being included.

PHP doesn't do that. Which is kind of annoying, but you get used to it.. But
I've come up with a work around.

htdocs/index.php
include('./system/core.php');

htdocs/system/core.php
define('CORE_PATH', str_replace('core.php', '', __FILE__));
include(CORE_PATH.'logic/engine.php');

htdocs/system/logic/engine.php
include(CORE_PATH.'html/header.php');

and so on and so forth. searching for __FILE__, and removing the filename
from the output, gives you a sort of relative path hack.

Hope someone finds that useful


You could also simply use the $DOCUMENT_ROOT variable
prepopulated for you ($_SERVER['DOCUMENT_ROOT'] perhaps?) and
base your includes relative to that.


Michael Kimsal
http://www.phpappserver.com/
734-480-9961


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to