2009-12-28 10:28
浏览 16


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`)

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?

图片转代码服务由CSDN问答提供 功能建议

我有一个主要由两个表组成的数据库驱动导航: menus 和一个 menu_items ,这对纯粹的“静态”链接很好,但现在我需要一个动态链接(登录/注销)。

我的 menu_items table只包含指向admin中手动添加的页面的链接。 所以现在我需要调整表和模型,以便它可以处理“动态”链接。


  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,

菜单ID对应另一个表,例如1是主要导航,2可以是实用程序导航。 位置是指相对于显示菜单项的每个菜单的顺序。 链接只是一个字段,例如'/user/login'。 nn

我循环遍历每个菜单并创建导航容器并使用Zend Navigation进行此操作。 \ n


 &lt;?  php if($ this-&gt; identity == null){?&gt; 
&lt; p&gt;&lt; a href ='/ user / login'&gt; Login&lt; / a&gt;&lt; / p&gt; 
&lt;?  php} else {?&gt; 
&lt; p&gt;欢迎回来&lt;?php echo $ this-&gt; identity-&gt; first_name;?&gt;&lt; / p&gt; 
&lt; p&gt;要注销&lt;  a href ='/ user / logout'&gt;点击此处&lt; / a&gt;&lt; / p&gt; 

它看起来 就像我需要为每个菜单项的访问级别添加一个新列,然后更新我的菜单模型以考虑用户是否登录,并查询菜单项的新访问列值,或者沿着这些行查询。 有人有什么建议吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • douxiegan6468 2009-12-28 17:01

    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 and sign out pages in my navigation config:

          <label>Sign in</label>
          <label>Sign out</label>

    Then, in my ACL:

    // 'mvc:home' is wide open, 'user' role inherits from 'guest'
    $this->addResource(new Zend_Acl_Resource('mvc:user_signin'), 'mvc:home');
    $this->deny('user', 'mvc:user_signin', 'navigate');
    $this->addResource(new Zend_Acl_Resource('mvc:user_signout'), 'mvc:home');
    $this->deny('guest', 'mvc:user_signout', 'navigate');
    $this->allow('user', 'mvc:user_signout', 'navigate');

    That way, it's just another piece of navigation, and behaves like the rest, just with a little logic behind it.

    解决 无用
    打赏 举报

相关推荐 更多相似问题