SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast oneafrikan's Avatar
    Join Date
    Oct 1999
    Location
    London, Uk
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php includes, directory structure and keeping it together...

    Hi there

    I'm having a bit of difficulty sorting out my directory structure, for the best use of php includes and header/footers. In short I'm stumped and desperately need assistance so I can move forward.

    So, here it is:
    Basically, I've got an index file in the root directory, like so:

    root dir/index.php

    If you take a look at http://www.dragflick.com, you'll see the preliminary index.php file.

    http://www.dragflick.com/index2.php should give you an idea of the kind of header/footer system needed, with content files in lots of sub-directories.

    Now, the index2.php calls several include files, which I've done so as to make updating and editing easier and more modular, and they are named as so:

    root dir/inc_file1.htm
    root dir/inc_file2.htm
    etc....

    This works fine, and is quite useful I think for making content manageable, especially for someone who is literally groping his way around and through php.

    The problem is that I have content in sub-directories, and obviously the best way to incorporate the design of the site without having to re-code each page from scratch each time you make a change, is to make use of header and footer files, between which is your content, like so:

    PHP Code:

    <?php require('../site_header.htm');?>
    <div class="headerclass">Header</div>
    <div class="subheaderclass">This is the sub-header description</div>
    <div class="paragraph">

    this is the content

    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore 
    magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis 
    nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse 

    </div>
    <?php require('../site_footer.htm');?>
    Because the header and the footers all call files themselves (stylesheets, images and other include files etc) and also link to files in the directory system, I've had to rename the links to other files to reflect their place in the directory structure, with a ../filename.htm, for example - the "../" being the important bit.

    Now, my concern is that this may not be the right/best /most practical way to do this, and this is why I ask for help.

    The way I see it, there are three primary options:


    1. create an /inc/ directory and put all the included files here - that way, when the header/footer system is used, the files are called from the same relative place in the directory structure.

    2. use a database table to store the html code necessary for the header/footer system. I think this may be the best option, and the most extensible...? The problem I have with this option, is that I don't yet know how.

    So, if there is agreement that this is indeed the best option, then I would appreciate anyone pointing me to a "canned" script that may help, perhaps with some directions/tutorials for use.

    3. have two versions of the include files - one version for inclusion by files in the root directory, and another for files in sub-directories.

    I think this option is the worst, because it means the most work, and would be the hardest to maintain in the long run.


    So, there you have it ;-)
    Here's to hoping that someone can help me, and in the process, perhaps others as well!

    Thank you and regards
    Gareth
    Last edited by oneafrikan; Oct 16, 2001 at 07:27.
    -> www.oneafrikan.com ><-><><-><-><-><-><
    -> www.openboxsoftware.com ><><-><-><-><

  2. #2
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include and require

    I myself have one file that has all the functions to connect to the database print headers footers etc..

    In this php file I use functions like Header()

    So now if I want to print out stuff I just use:

    Header(var1, 2);
    echo"

    ";
    Footer();

    Or if it is more HTML and Javascripts and/or content I use

    <?
    Header(var1,2);
    ?>
    HTML content etc....

    <?
    footer();
    exit;
    ?>

    Stuff like that.. But I would just use 1 file and have that required at the begin of every file..

    Good Luck,

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  3. #3
    SitePoint Enthusiast oneafrikan's Avatar
    Join Date
    Oct 1999
    Location
    London, Uk
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks peanuts

    Hi there peanuts

    Thanks millions ;-)

    Would you mind passing on those functions?, and perhaps anything that may help me get it up and running...?, so I can give it a try locally, and see if it would work for me...

    Thanks for the post. ;-)

    Anybody got any other comments/ideas/tools etc that may help with this problem?

    Regards
    Gareth
    -> www.oneafrikan.com ><-><><-><-><-><-><
    -> www.openboxsoftware.com ><><-><-><-><


Bookmarks

Posting Permissions

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