dry69034 2016-01-29 12:07
浏览 87
已采纳

如何根据Code igniter中的用户类型自定义导航

I am building web application with 4 type of users and starting from top level(Admin) to lower level(end-user) , access rights for specific tab will be eliminated.

I have consider idea of using html helper but in this case I am not able to assign class and attributes to my li elements.

$this->load->helper('html');

$list = array(
            'level 1', 
            'level 2', 
            'level 3',
            'level 4'
            );

$attributes = array(
                    'class' => 'boldlist',
                    'id'    => 'mylist'
                    );

echo ul($list, $attributes);

let me know , how can I add attributes to list item.

Above mentioned code will generate this.

<ul class="boldlist" id="mylist">
  <li>level 1</li>
  <li>level 2</li>
  <li>level 3</li>
  <li>level 4</li>
</ul>
  • 写回答

2条回答 默认 最新

  • douchao1864 2016-01-29 12:10
    关注

    You could do it manually:

    $ul[0]['list'] = array(
        'level 1' => array('class' => 'test'), 
        'level 2',
        'level 3',
        'level 4'
    );
    
    $ul[0]['attributes'] = array(
        'class' => 'boldlist',
        'id'    => 'mylist'
    );
    
    foreach ($ul as $_ul) {
        echo '<ul';
        // add attributes
        foreach ($_ul['attributes'] as $_ulak => $_ulav) {
            echo ' '.$_ulak.'="'.$_ulav.'"';
        }
        echo '>';
    
        // add list items
        foreach ($_ul['list'] as $_ullk => $_ullv) {
            if (is_array($_ullv)) {
                echo '<li';
                // add list attributes
                foreach ($_ullv as $_ullvk => $_ullvv) {
                    echo ' ' . $_ullvk . '="' . $_ullvv . '"';
                }
                echo '>';
                echo $_ullk;
            } else {
                echo '<li>' . $_ullk;
            }
            echo '</li>';
        }
        echo '</ul>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?