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

  • 写回答

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:

        <user_signin>
          <label>Sign in</label>
          <other_stuff></other_stuff>
          <resource>mvc:user_signin</resource>
          <privilege>navigate</privilege>
        </user_signin>
    
        <user_signout>
          <label>Sign out</label>
          <other_stuff></other_stuff>
          <resource>mvc:user_signout</resource>
          <privilege>navigate</privilege>
        </user_signout>
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路