Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    73
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Nested directories and creating a dynamic link to them

    I am working on creating a very basic cms system. Just doing it to improve my understanding on how PHP works. Here is my problem.
    When I create my basic HTML type site, I separate the header, navigation, content and footer areas into includes.

    This way, if I change a link in the footer or header, I only have to change one file not ten.

    The problem I am running into is when I want to call those includes from within a sub-directory. If I call those files from the sub directory (i.e. root/products) the links in the header and footer won't work because those links are now looking within the folder where the file has been called.

    What would be the best way to solve the problem?

    I have thought about creating some sort of variable to place in front of the link:

    PHP Code:
    <?php 
    if(some php voodoo to determine if the file is in a subfolder or not...){
    $directory "../";
    }else{
    $directory "";
    }
    ?>

    <a href="<?php echo $directory?>/web_link.php">Web Link</a>
    Any ideas on the best way to work this problem?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I'd use absolute paths like
    Code:
    <a href="/file1.php">file inside root</a>
    <a href="/dir1/file1.php">file inside dir1</a>
    <a href="/dir1/dir2/file1.php">file inside dir1/dir2</a>
    Check http://www.codingforums.com/showpost...67&postcount=9
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    73
    Thanks
    11
    Thanked 0 Times in 0 Posts
    The only problem with using the absolute paths is that I would have to create a second file. One for the root and one for a sub directory.

    I am looking at how CMS systems work and they have managed to get links to work inside of directories. I guess I am trying to replicate that functionality without having to install a full blown CMS system.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The only problem with using the absolute paths is that I would have to create a second file. One for the root and one for a sub directory.
    Not really! How did you conclude like that?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •