How to group variables for a hierarchical menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

How to group variables for a hierarchical menu

Post by asgerhallas »

Hi,

I'm using an object to keep track of items in a hierarchical menu, like this:

Code: Select all

class menu
{
    var $nodes;

    function addbranch()
    {
     ....
    }
}

Now $nodes should hold information about title and an array for subnotes. By now I'm holding these in another class like this:

Code: Select all

class node
{
     var $title;
     var $nodes;
}

Is this the best way to do it? I like the readability, but is there other ways to do the same having for example in just one class? Or faster?

Or does anyone maybe know a class outthere somewhere, which will be a good foundation for turning my database information in to a HTML-list? (I'm using the adjacency list model for storing the items hierachical)...

Any suggestions highly appriciated.

/Asger
Post Reply