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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题