I have a database driven navigation mainly composed of two tables: menus
and a menu_items
, this works out fine for purely "static" links but now I need to have a dynamic link ( login/logout ).
My menu_items
table is just composed of links to pages manually added in the admin. So now I need to adjust the table and model possibly such that it can handle "dynamic" links.
Here's the schema for the menu_items table:
CREATE TABLE `menu_items` (
`id` int(11) NOT NULL auto_increment,
`menu_id` int(11) default NULL,
`label` varchar(250) default NULL,
`page_id` int(11) default NULL,
`link` varchar(250) default NULL,
`position` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8
Menu id corresponds to another table, so 1 for example is the primary nav, 2 can be utility nav. Position refers to the order relative to each menu in which the menu item is displayed. Link is just a field, eg '/user/login'.
I'm looping through each of my menus and creating Navigation containers and using Zend Navigation for this.
Here's logic I'm using for my login area, I'll need to move this over and incorporate it into the dynamic navigation:
<?php if($this->identity == null) { ?>
<p><a href='/user/login'>Login</a></p>
<?php }else{ ?>
<p>Welcome back <?php echo $this->identity->first_name;?></p>
<p>To log out <a href='/user/logout'>click here</a></p>
<?php } ?>
It looks like I need to add a new column for access level for each of the menu items, then update my Menu model to account for whether the user is logged in or not and query the menu item's new access column value, or something along those lines. Anyone have any suggestions?
Gordon's ACL is the way to go (and I upvoted it). I just wanted to pipe in and describe exactly what I do.
I created both the
sign in
andsign out
pages in my navigation config:Then, in my ACL:
That way, it's just another piece of navigation, and behaves like the rest, just with a little logic behind it.