Hallo,
Ik ben sinds deze week bezig met PHP en heb 2 OO-classes gedefinieerd
die een statisch uitklap-menu genereert.
Ik heb thuis PHP versie 5.01 en m'n provider draait versie 4.3.8
Nu blijkt het script helaas niet te werken bij de provider. En dit
bevreemt mij, want de syntax is gewoon gelijk gebleven. De logging op de
server is ook vreemd.
// -------------------- code ------------------------
<?php
class Menu
{
// constructor
function Menu( $sOmschrijving)
{
$this->omschrijving = $sOmschrijving;
$this->subitems = array();
$this->bCurrent = false;
}
// voeg een item toe aan het menu
function AddSub( $subitem)
{
array_push( $this->subitems, $subitem);
if( $subitem->isCurrent())
{
echo ("Menu({$this->omschrijving}) wordt true<br/>"); // DEBUG
$this->bCurrent = true;
}
return( $subitem);
}
// schrijf het menu
function Write( $nivo=0)
{
if( count( $this->subitems))
{
echo "<table ".($nivo ? " class=\"submenu\"" : "").">";
foreach( $this->subitems as $item)
{
$item->Write($nivo);
}
echo "</table>";
}
}
function isCurrent()
{
$bRetval = $this->bCurrent;
echo ("{$this->omschrijving}.isCurrent(): $bRetval<br/>"); // DEBUG
return( $bRetval);
}
}
class MenuItem extends Menu
{
function MenuItem( $sOmschrijving, $sURL)
{
$this->omschrijving = $sOmschrijving;
$this->url = $sURL;
$this->bCurrent = false;
$this->subMenu = new Menu($sOmschrijving);
if( $_SERVER["SCRIPT_NAME"] == $sURL)
{
$this->bCurrent = true;
}
}
function AddSub( $subitem)
{
$this->subMenu->AddSub( $subitem);
if( $subitem->isCurrent())
{
echo ("MenuItem({$this->omschrijving}) wordt true<br/>"); // DEBUG
$this->bCurrent = true;
}
return( $subitem);
}
/*------------------------
Schrijf een menu-item.
Als Current && hoofdnivo, wordt de omschrijving H1
------------------------*/
function Write( $nivo=0)
{
$bCurrent = $this->isCurrent();
echo "<tr><td>";
if( ($nivo == 0) && bCurrent)
echo "<h1>";
echo "<a href=\"{$this->url}\">{$this->omschrijving}</a>";
if( $bCurrent)
{
if( !$nivo)
echo "</h1>";
$this->subMenu->Write( $nivo+1);
}
echo "</td></tr>\n";
}
}
$menu = new Menu("hoofdmenu");
$home = $menu->AddSub( new MenuItem( "Home", "/index.php"));
$aanbod = $menu->AddSub( new MenuItem( "Aanbod", "/aanbod.php"));
$resultaten = $menu->AddSub( new MenuItem( "Resultaten",
"/resultaten.php"));
$werkwijze = $menu->AddSub( new MenuItem( "Caroline Reij",
"/werkwijze.php"));
$werkwijze->AddSub( new MenuItem( "Achtergrond", "/caroline.php"));
$samen = $menu->AddSub( new MenuItem( "Samenwerking", "/samenwerking.php"));
$samen->AddSub( new MenuItem( "Links", "/links.php"));
$contact = $menu->AddSub( new MenuItem( "Contact", "/contact.php"));
$contact->AddSub( new MenuItem( "Routebeschrijving", "/route.php"));
?>
// -------------------- einde code ------------------------
// -------------------- debug log ------------------------
Home.isCurrent():
Aanbod.isCurrent():
Resultaten.isCurrent():
Caroline Reij.isCurrent():
Achtergrond.isCurrent():
Achtergrond.isCurrent():
Samenwerking.isCurrent():
Links.isCurrent():
Links.isCurrent():
Contact.isCurrent():
Routebeschrijving.isCurrent(): 1
Menu(Contact) wordt true //<<-- contact wordt true!
Routebeschrijving.isCurrent(): 1
MenuItem(Contact) wordt true
Home.isCurrent():
Aanbod.isCurrent():
Resultaten.isCurrent():
Caroline Reij.isCurrent():
Samenwerking.isCurrent():
Contact.isCurrent(): //<<-- en nu niet meer???
// -------------------- einde debug log ------------------------
--
Arjen Haayman
-- cogito ergo bicyclo --

Likes:

Quote