I am building a recursive Menu object.  Inside each menu item there is an array which 
should allow me to add submenu items and so on.  I am having trouble, though, with 
getting the submenus to stay.  They are disappearing as I go along.

Here is the menu class:  (part of it anyway)

class Menu {
 var $iMenuId;
 var $iParentId;
 var $iMasterId;
 var $sMenuName;
 var $sMenuType;
 var $bStatus;
 var $vecMenu;   // <- This is the array of submenus which 
                 //    will each have their own submenus
 
 function Menu ($iMI, $iPI, $iMstI, $sMN, $sMT, $bS){
  $this->iMenuId   = $iMI;
  $this->iParentId  = $iPI;
  $this->iMasterId = $iMstI;
  $this->sMenuName = $sMN;
  $this->sMenuType = $sMT;
  $this->bStatus  = $bS;
  $this->vecMenu  = array();
  
 // Used as static variable since PHP4 doesn't support them.
  global $menuCount; 
  $menuCount++;
 }
 
 function bIsMaster(){
  return ($this->iMasterId == $this->iMenuId);
 }
 
 function bIsParent(){
  return ($this->iParentId == $this->iMenuId);
 }
 
 function bAddMenu(&$m) {
  
  if ($m->bIsParent() && $m->bIsMaster())
   return false;
  
  if ($this->iMenuId == $m->iParentId){
   $this->vecMenu[] = &$m;              //  <-  This is a guess.  
                                        //      Added into vector by reference?
   return true;
  }
  
  for ($i=0; $i < count($this->vecMenu); $i++){
   $tmpMenu = $this->vecMenu[$i];
   if ($tmpMenu->bAddMenu (&$m))
    return true;
  }
  
  return false; 
 }
  
 
} //END Menu Class



Should this work?  Am I just doing something completely wrong?  I know someone out 
there knows, please let me know if you have any ideas.  I really appreciate any help I 
can get.

Thanks in advance.

-- 
Joshua Groboski
Programmer Analyst
SAVVIS Communications Inc.
http://www.savvis.net

Reply via email to