Please note: This is an unpublished site and we are making changes - glitches still!!!

A Simple Menu Module

Creating a beautiful, flexible menu module is a true pain. There are quite a few commercial menu builders available but building a nice menu is not too hard. To keep things simple we will not try to make use of the most elaborate Ajax methods let alone Flash or Silverlight. Instead, we will write a very, very simple vertical HTML menu. Well, you know, the system is modular and you can replace the original module any time later. 
 
You wil notice that the menu we are creating is one-dimensional without subitems. Do not worry! We will build a better one later with two nice levels.

The DB table

The menu we will create is a simple one-level-only and the data is kept in a database table so it is easy to write an administration utility for it. Please note that we have included space for future extension (menuid,linktype and parent id).
 
simplemenu.sql

The template

Now the next task is to write a template which is very simple once you figure out how the UL based menu works:
 
ulmenu.tpl
 
Save the template as templates/ulmenu.tpl.

The module code

It is no problem writing the module, either. Here it is in all its complexity

CascadedMenu_module.php

Save the module as modules/menus/CascadedMenu_module.php

Now replace the HTML menu code from the main template with this:



 
After you have done this it is very simple to add a couple of menu items by hand using the MySQL administration tool of your choice:
 
INSERT INTO simple_menuitems(idx,menutext,url) VALUES (1,'Front page','/front_page');
INSERT INTO simple_menuitems(idx,menutext,url) VALUES (2,'Another  page','/products');
 
All right! Now it is time to create an administration tool. That might sound like a formidable job. I admit it is but the result will be second to none.