Home > Archive > PHP Language > April 2005 > using a menu in multiple pages
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using a menu in multiple pages
|
|
|
| I am want to use a menu in all my web pages.
So when I replace the menu for another
I would like to see all the other pages change too.
In C I could use an include in the preprocessor stage.
Is there something in PHP or html?
| |
| Kimmo Laine 2005-04-15, 3:56 pm |
| "fed" <u@dds.nl> wrote in message news:c_N7e.3531$HP5.2080@newsfe01.lga...
>I am want to use a menu in all my web pages.
> So when I replace the menu for another
> I would like to see all the other pages change too.
>
> In C I could use an include in the preprocessor stage.
> Is there something in PHP or html?
In php there is. Magically it's called include.
<?php include "my_menu.txt"; ?>
Example.php:
<html><head></head>
<body>
<?php include "my_menu.txt"; ?>
Blaah blaah bblaah
</body>
</html>
my_menu.txt:
<p>Here's my über menu</p>
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
| |
| Colin McKinnon 2005-04-15, 3:56 pm |
| fed wrote:
> I am want to use a menu in all my web pages.
> So when I replace the menu for another
> I would like to see all the other pages change too.
>
> In C I could use an include in the preprocessor stage.
You could...but you shouln't.
> Is there something in PHP or html?
Yes, both.
RTFM http://uk2.php.net/function.include
C.
| |
| coolsti 2005-04-18, 8:55 am |
| On Fri, 15 Apr 2005 13:56:51 +0200, fed wrote:
> I am want to use a menu in all my web pages.
> So when I replace the menu for another
> I would like to see all the other pages change too.
>
> In C I could use an include in the preprocessor stage.
> Is there something in PHP or html?
You want a common piece of code to be run on all the pages of your
application, and you want to be able to modify this code in only one
centralized location, so that the modification will then occur for your
entire application. Is that what you wish?
You can do this with PHP.
Create a function, or a class, which produces the menu, and call this
function (or instantiate the class) on each page where the menu is to
appear. Put the function (or class) in a php file of its own, along with
other common functions and classes. Then "include" this code in any php
script which needs it with a require statement (require $filename where
$filename is the name of the file, and possibly its path if not located
where expected by php). If your code is very complicated and you start to
have problems including the same files multiple times (giving you errors),
you could use require_once instead.
To make changes, you can edit the function or class. Or you can make the
function or class be dynamic, by having it determine its output (i.e. its
generated html code) based on for example reading another file with a
require statement (this time perhaps only text), or a switch statement (if
you have set types of menus you want to always choose between) or from a
database. This latter really gives you full flexibility of what you can do.
| |
| coolsti 2005-04-20, 8:56 pm |
| On Fri, 15 Apr 2005 13:56:51 +0200, fed wrote:
> I am want to use a menu in all my web pages.
> So when I replace the menu for another
> I would like to see all the other pages change too.
>
> In C I could use an include in the preprocessor stage.
> Is there something in PHP or html?
You want a common piece of code to be run on all the pages of your
application, and you want to be able to modify this code in only one
centralized location, so that the modification will then occur for your
entire application. Is that what you wish?
You can do this with PHP.
Create a function, or a class, which produces the menu, and call this
function (or instantiate the class) on each page where the menu is to
appear. Put the function (or class) in a php file of its own, along with
other common functions and classes. Then "include" this code in any php
script which needs it with a require statement (require $filename where
$filename is the name of the file, and possibly its path if not located
where expected by php). If your code is very complicated and you start to
have problems including the same files multiple times (giving you errors),
you could use require_once instead.
To make changes, you can edit the function or class. Or you can make the
function or class be dynamic, by having it determine its output (i.e. its
generated html code) based on for example reading another file with a
require statement (this time perhaps only text), or a switch statement (if
you have set types of menus you want to always choose between) or from a
database. This latter really gives you full flexibility of what you can do.
|
|
|
|
|