我有一个主要由两个表组成的数据库驱动导航: 我的 这是menu_items表的模式: p>
菜单ID对应另一个表,例如1是主要导航,2可以是实用程序导航。 位置是指相对于显示菜单项的每个菜单的顺序。 链接只是一个字段,例如'/user/login'。 p>
nn 我循环遍历每个菜单并创建导航容器并使用Zend Navigation进行此操作。 p> \ n
这是我用于登录区域的逻辑,我需要将其移动并将其合并到动态导航中: p>
它看起来 就像我需要为每个菜单项的访问级别添加一个新列,然后更新我的菜单模型以考虑用户是否登录,并查询菜单项的新访问列值,或者沿着这些行查询。 有人有什么建议吗? p>
div> menus code>和一个
menu_items code>,这对纯粹的“静态”链接很好,但现在我需要一个动态链接(登录/注销)。 p>
menu_items code> table只包含指向admin中手动添加的页面的链接。 所以现在我需要调整表和模型,以便它可以处理“动态”链接。 p>
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)默认为NULL,
`link` varchar(250)默认为NULL,
`position`int(11)默认为NULL,
PRIMARY KEY(`id`)
)ENGINE = InnoDB AUTO_INCREMENT = 18 DEFAULT CHARSET = utf8
code> pre>
<? php if($ this-> identity == null){?>
< p>< a href ='/ user / login'> Login< / a>< / p>
<? php} else {?>
< p>欢迎回来<?php echo $ this-> identity-> first_name;?>< / p>
< p>要注销< a href ='/ user / logout'>点击此处< / a>< / p>
<?php}?>
code> pre>
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?