Re: Here is a silly question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Apr 3, 2006, at 10:54 AM, Mace Eliason wrote:

Hi,

This is come thing that I have struggled with now and again. I usaually us php code to make it work, but was wondering how others deal with this

I use includes in most of the web applications that I work on to include the header, footer, menu etc.

The problem that I always run into as a project gets bigger is my links to pages. If all the files are in the root directory theres no problem.

If I have some files in a folder and call my menu for example <? include("../menu.php"); ?> I have to call if from the parent directory. But then of course
all the links are wrong.  Root becomes the calling directory.

I usually use a php variable to place the ../ if its needed.

How does everyone else deal with this type of problem. I have a times places an extra copy of the footer, menu, header etc in each directory but it is a pain to change links
when you have multiple locations to do it in.

Thanks for any suggestions.

I would be nice to have a simple way to have my include files in a common place that works and keeps the links right.

Scandog


Ok, I this may only help part of your problem. Within your "menu.php" file, you could make all the links absolute:

<a href="/root/to/a/location.php">Place A</a>
<a href="/root/to/somewhere.php">Place B</a>

instead of relative:

<a href="location.php">Place A</a>
<a href="somewhere.php">Place B</a>

That means you can use only 1 menu.php file and all the links will work from wherever. Of course, this does not fix this issue:

<? include ("../../menu.php"); ?> or
<? include ("menu.php"); ?> or
<? include ("../somewhere/menu.php"); ?>

for each of your files that includes the menu. Maybe another clever person has an idea.

~Philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux