[Q] Working with Include

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    [Q] Working with Include

    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... ===
  • Eric

    #2
    Web Site Design ( was Re: [Q] Working with Include)

    Eric <egDfAusenetE5f z@verizon.net> wrote:
    [color=blue]
    > 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?[/color]

    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=\"director yname\">linknam e</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 . "locationFromSi teRootDir";
    echo "<a href=\"$locatio n\">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.

    Comment

    Working...