Wednesday, March 21, 2012

Database menu structure

Hello,
I am upgrading my (simple) cms from one menu layer to two layers. So i have two tables in de my DB
- table_mainmenu
- table_submenu
The submenu records are linked to the mainmenu records on the mainmenu id. So far so good. Heres my problem, i cant figure out how to change the order of the pages...!? What is the theory behind recording the stacking order of the menu items? How can i record this information in the DB?
I just need the theory, i can figure out the details for myself. Thanks in advance!
Corstiaan
p.s. is the the right forum to post this?

Actually, you do not need two tables, one table should work, for example, Menu table, you need a parentId coulmn in Menu table so menuitem can seft reference itself, now you not only have two-level but also mutiple-level menu using recursive function. You can have a displayOrder column for order of menuitem.

|||Thanks for your reply.
So i need only one table? Thats nice. Do you perhaps have a DB example of your theory?
Thanks you very much!
Corstiaan|||

See below table structure:
Table Menu:
MenuId
MenuName
ToolTip
Url
DisplayOrder: This is a numeric value for display order on the menu
ParentId : The id of the parent menu item. For the main menu the value is 0.
Also you need use recursion to build submenus in your code, basically you need a Menu base class and inheritance MenuItem class, and MenuBuilder class to build your menu system.


|||Ok so if i get this straight, all pages are in the same table, no matter the level? And the parent ID has a value of any record (in the same table) that the user whats to be the parent page? Right?
Hmm maybe is would be nice after all if you could provide me with same (code) examples for organizing the parent ID and display order? Very much appreciated!
Corstiaan

No comments:

Post a Comment