[thelist] PHP -Self-finding navigational includes
Kasimir K
evolt at kasimir-k.fi
Thu Jul 28 07:58:10 CDT 2005
Fred D Yocum scribeva in 2005-07-28 12:25:
> Using PHP to create a repeating object like a navigational sidebar with an
> include file seems like a good idea. This is trivial to accomplish If all
> the paths are either absolute
> (http://somewhere.com/thisdirectory/thatfile.html) or everything is at the
> same directory level, the links can be hard coded. If they're not, you
> need a function/routine that figures out where the page (with the
> included navigational side bar) is within the directory structure and
> writes the paths accordingly. ... Can
> anyone point me in the direction of an efficient way of doing this?
I use constants for this, e.g:
if (!defined('INCLUDE_ROOT')) {
define('INCLUDE_ROOT','../');
}
require_once(INCLUDE_ROOT . 'foo/bar/menu.php');
or
echo "<a href='" . INCLUDE_ROOT . "foo/bar.html'>bar</a>";
I define INCLUDE_ROOT in every file. If a file itself is included in
another file, then INCLUDE_ROOT is alredy defined in the including file,
thus it is always correct and I can use it anywhere without any worries.
Joy!
.k
More information about the thelist
mailing list