|
» W3Exchange http://www.w3exchange.com/index.html » PHP http://www.w3exchange.com/view_forum-id-36.html » Calling PHP functions in a Menu http://www.w3exchange.com/view_topic-id-108.html |
| kibanga - 2006-08-30 03:05:43 |
I have files of several with geographical information of several places and animals that i want to be accesed by through the menu. Here is an outline of my project; I have simplified it by taking only parts that are relavent for my questions below. Code::<?php//=================================================
//mymain.html
class mysite
{ var $pagetitle;
var $pagefile;
function setsite($title,$contents)
{
$this->pagetitle=$title;
$this->pagefile=$contents;
}
function menu()
{
include_once("mymenu.html");
}
function content()
{
$pagetitle=$this->pagetitle;
$contentsfile=$this->pagefile;
include_once("mycontents.html");
}
}
//=================================================
?>The function menu calls a "mymenu.html" file to set up the menus. A typical setup of myenu.html is as follows: Code::<?php
//=================================================
// mymenu.html.
?>
<div class="menu">
<ul>
<li class="Animals"><a href="..">Animals
<table><tr><td>
<ul>
<li class="Elephants"><a href="..">Elephants</a></li>
<li class="Lions"><a href="..">Lions</a></li>
<li class="Zebras"><a href="..">Zebras</a></li>
</ul>
</td></tr></table></a>
</li>
<li class="Places"><a href="..">Places
<table><tr><td>
<ul>
<li class="Brazil"><a href="..">Brazil</a></li>
<li class="South Africa"><a href="..">South Africa</a></li>
<li class="Malaysia"><a href="..">Malaysia</a></li>
</ul>
</td></tr></table></a>
</li>
</ul>
</div>
?>As it can be seen, this menufile is not complete; that is where my questions are. Before I pose my questions, let me finish up a few more codes. Code::<?php
//=================================================
// mycontents.html.
?>
<h2><? echo $pagetitle;?></h2>
<hr>
</div>
<?
include_once($contentsfile);
//=================================================
?>Basically, the contes file displays the $pagetitle, and opens a $contentsfile. Someone may question this organisation but my actual file larger file requires it to be so. Code::<?php
//=================================================
// mymain.html.
include_once("mysitecls.html");
$thissite = new mysite;
$thissite->setsite("My World Travels","mydefault_contents.html");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<html>
<head>
<title><?echo $thissite->pagetitle?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="all" type="text/css" href="far-mex.css" />
</head>
<body>
<div id="leftcol" >
<? $thissite->menu(); ?>
</div>
<div id="leftcol" >
<? $thissite->content();?>
</div>
</body>
</html>
<?
?>Basically it initilizes the class with a file tile of "My World Travels" where the file contents are in "mydefault_contents.html". After that the user through the menu selects what a topic to be displayed, each selection has to set up a string with for $pagetitle (i.e the title of the topic) and a string for the $pagefile (i.e. file name with details of the topic). This construction is in complete in the menufile shown above, which is the center of my questions: |
» Print this topic |