User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,976 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,129 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Basic PHP Includes

Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
robothy robothy is offline Offline
Light Poster

Re: Basic PHP Includes

  #2  
May 10th, 2008
Hi,

This is a topic I am having an issue with presently.

I have separated my HTML code from my PHP code, so that I now have a header, footer and navigation template, which will be used on every webpage. Then the content is the only aspect that will change from page to page (well, and some other parts such as the login/logout box, etc).

The issue I am encountering is that the links in my navigation menu are static and therefore cannot adapt if the menu is included in a page that is a directory deeper in my website. E.g.:

+ public_html
+ - index.php
+ - news
+---+ - index.php
+ - another dir
+---+ - index.php


Therefore, if I include the navigation in the index.php page in the base of the public_html directory, everything works fine. If I however include it in the index.php in the news directory, the links are all one level off.

I've considered two solutions for this, neither of which I like very much. The first is to use absolute file references, so the full path '/website/home/templates/navigation/navigation.tpl', but this could be a problem if I want to use the code somewhere else, where the structure is different. I wouldn't want to have to edit every link.

The other method I considered was to pass a parameter to my templating engine defining the directory structure offset, which is the appended to the beginning of any path before it is used. So for the base directory, this would be either an empty string, '', or '.' . For a directory deeper it would be 'dirname', and a directory higher './../' or '..' .

Again however, this solution looks messy. Can anyone suggest a better solution please?

If you've made it this far, thanks for reading. Please find a beer with your name on it in the bar I know I need one.

R.
Last edited by robothy : May 10th, 2008 at 6:04 am.
Reply With Quote  
All times are GMT -4. The time now is 9:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC