[Q] Working with Include

  • Follow


I've got a directory structure similar to this:

  index.php

  dirA
    index.php

  dirB
    funcs.php

  otherfuncs.php

in the root index.php, I've got:

  require_once( dirB/funcs.php );

in funcs.php, I've got:

  require_once( otherfuncs.php );

which works because the root index.php is the location from which files
are looked for.


In dirA/index.php, I've got:

  require_once( ../dirB/funcs.php );

However, now, require_once( otherfuncs.php ) in funcs.php cannot be
found.


I can provide full a full path in each of the requires, but this would
lead to rather unstable code....or is this the right way to do things?

How do you work around this kind of issue?

Thank you.


-- 
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both 
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
0
Reply egDfAusenetE5fz (78) 2/2/2004 4:04:49 PM

Eric <egDfAusenetE5fz@verizon.net> wrote:

> I can provide full a full path in each of the requires, but this would
> lead to rather unstable code....or is this the right way to do things?

Well, a solution I found to this problem was in dirA/index.php, to
chdir( ".." ); before the require_once ... is this the best way to solve
this problem?


Also, funcs.php contains statements of the form:

echo "<a href=\"directoryname\">linkname</a><br>";

forming a relative URL. Again, this would point to a different
location depending on whether dirA/index.php or SiteRootDir/index.php
called the function containing this relative URL.

I was able to find a solution by doing the following:

function AFunction( $toRoot )
{
$location = $toRoot . "locationFromSiteRootDir";
echo "<a href=\"$location\">linkname</a><br>";
}

So, from dirA/index.php, I would call AFunction like:

AFunction( ".." );

Is this the best way to solve this problem?

Thank you.
0
Reply egusenet (56) 2/4/2004 5:51:47 PM


1 Replies
17 Views

(page loaded in 0.131 seconds)


Reply: