Let me start by saying this will not work out of the box, you will need to create a database object and a user object to work with this code...
when you create the methods for those 2 classes, make sure you edit these 3 menu class files so that the method calls reflect the methods in your user and database class.
Ok so i have expanded on my menu objects. You can now have it be dynamic based on the user level of the user viewing. In my system i have a user object that handles the users, there are several different user levels, they each have a numeric and text label. I store my user levels in a database and then grab them and turn them into constants. So when you see a reference in this code think of a user level say 0 and the text is Guest 1 and text is User etc..
let me start by showing the database scheme and explain them.
The Menu Group Table
CREATE TABLE `menu_groups` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(20) NOT NULL default '',
`req_level` int(2) NOT NULL default '0',
`login_display` int(1) NOT NULL default '0',
`display_order` int(2) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
id = the group id (obviously)
title = the textual name of the group
req_level = the required user level in integer format
login_display = show this group if the user is logged in? 0/1 format
display_order = the order in which to display this group
The Menu Items Table
CREATE TABLE `menu_items` (
`id` int(11) NOT NULL auto_increment,
`mgroup` int(11) NOT NULL default '0',
`title` varchar(20) NOT NULL default '',
`link` varchar(25) NOT NULL default '',
`req_level` int(2) NOT NULL default '0',
`login_display` int(1) NOT NULL default '0',
`display_order` int(2) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
id = the item id (obviously)
mgroup = the id of the group this item belongs to
title = the textual name of the item
link = either a filename or a full out url to a page
req_level = the required user level in integer format
login_display = show this group if the user is logged in? 0/1 format
display_order = the order in which to display this item
the display order is an integer format you can use to set the order of display 1,2,3,4,5,6,7,8,9 etc,,, if you have 2 items and you set the display order to be 10,100 the one with the lowest order is shown first.
ok so with that explained let's move on to the actual code in this small application.
<?php
// include the class file.
include_once( 'Menu.class.php' );
// create an instance of the object.
$menu = new Menu( $db_object );
// place this wherever you want to draw the menu
$menu->Draw( $user_object );
?>
Here is an example menu (user not logged in)
General
Home
FAQ
Rules
Control Panel
Login
Register
Here is an example menu (user logged in)
General
Home
FAQ
Rules
Staff
Community
Forums
Chat Stats
Live Chat
Control Panel
Logout
Notice how Login and Register are no longer shown. This is because i have them set in the database. I have set the login_display to 0 so that they would not be shown.
Attached you will find the 3 class files for the menu object.
As always, any questions or need help getting this started just email me