菜单列表基于角色codeigniter

时间:2016-09-23 04:35:35

标签: php codeigniter-3

如何动态地根据树视图中的角色显示我的菜单列表?我曾经像这样显示我的角色菜单,但是在主菜单上没有工作,但是我已经尝试了很多不同的东西,但我不知道如何正确显示它

<div class="module_item">
    <?php foreach ($fields as $session) : ?>
        <?php foreach ($session['data'] as $itemData) : ?>
            <div class="module_item" title="<?= $itemData['value'] ?>">
                <a href="<?= $itemData['url'] ?>"><img src="<?= $itemData['icon'] ?>"/></a>
                <a href="<?= $itemData['url'] ?>"><?= $itemData['value']?></a>
            </div>
        <?php endforeach ?>
    <?php endforeach ?>
</div>

那我该怎么做呢?

控制器

public function getModules($id_module){
    if($this->session->userdata('log')){
        $data = $this->session->userdata('log');
        $menu = array();
        $seccions = $this->module->get_rows();
        foreach ($seccions as $index => $seccion){
           $modules = $this->module->query("SELECT CONCAT('".$seccion['id']."',storelte_modulo.id) AS id,CONCAT('".base_url('assets/img/sidebar')."','/',storelte_modulo.icon) as icon, storelte_modulo.modulo AS value,storelte_modulo.seccion_id,CONCAT('".base_url()."',storelte_modulo.url) AS  url FROM storelte_modulo INNER JOIN storelte_modulo_perfil ON  storelte_modulo_perfil.modulo_id = storelte_modulo.id WHERE seccion_id = $seccion[id] AND storelte_modulo_perfil.perfiles_id = $data[id] AND storelte_modulo_perfil.STATUS = 1");
            $seccions[$index]['data']= $modules;
            if (!count($seccions[$index]['data']))
                unset($seccions[$index]);
        }
        foreach ($seccions as $item)
            array_push($menu,$item);
      $this->data['fields'] = $menu;
      $this->json($this->data);
    }
}

视图

<section class="sidebar">
  <!-- sidebar menu: : style can be found in sidebar.less -->
  <ul class="sidebar-menu">
     <li class="treeview">
      <a href="#">
        <img src="<?= base_url().'/assets/img/sidebar/items.png'?>" alt="" class="menu-icon"> <span>Inventory</span>
        <i class="fa fa-angle-left pull-right"></i>
      </a>
      <ul class="treeview-menu">
        <li><a href="<?=base_url('inventory/product');?>"><i class="fa fa-circle-o text-aqua"></i> Product</a></li>
      </ul>
    </li>
    <li class="treeview">
      <a href="#">
        <img src="<?= base_url().'/assets/img/sidebar/suppliers.png'?>" alt="" class="menu-icon"> <span>Purchase</span>
        <i class="fa fa-angle-left pull-right"></i>
      </a>
      <ul class="treeview-menu">
         <li><a href="<?=base_url('inventory/provider');?>"><i class="fa fa-circle-o text-aqua"></i> Provider</a></li>
      </ul>
    </li>
    <li class="treeview">
      <a href="#">
        <img src="<?=base_url().'/assets/img/sidebar/sales.png'?>" alt="" class="menu-icon">
        <span>Sale</span>
      </a>
    </li>
    <li class="treeview">
      <a href="#">
         <img src="<?=base_url().'/assets/img/sidebar/barchart.png'?>" alt="" class="menu-icon"> <span>Charts</span>
        <i class="fa fa-angle-left pull-right"></i>
      </a>
      <ul class="treeview-menu">
        <li><a href="#"><i class="fa fa-circle-o text-red"></i> Best selling product</a></li>
      </ul>
    </li>
    <li class="treeview">
      <a href="#">
        <img src="<?=base_url().'/assets/img/sidebar/employees.png'?>" alt="" class="menu-icon"> <span>User</span>
        <i class="fa fa-angle-left pull-right"></i>
      </a>
      <ul class="treeview-menu">
        <li><a href="pages/examples/invoice.html"><i class="fa fa-circle-o"></i> Invoice</a></li>
        <li><a href="pages/examples/profile.html"><i class="fa fa-circle-o"></i> Profile</a></li>
        <li><a href="pages/examples/login.html"><i class="fa fa-circle-o"></i> Login</a></li>
        <li><a href="pages/examples/register.html"><i class="fa fa-circle-o"></i> Register</a></li>
        <li><a href="pages/examples/lockscreen.html"><i class="fa fa-circle-o"></i> Lockscreen</a></li>
        <li><a href="pages/examples/404.html"><i class="fa fa-circle-o"></i> 404 Error</a></li>
        <li><a href="pages/examples/500.html"><i class="fa fa-circle-o"></i> 500 Error</a></li>
        <li><a href="pages/examples/blank.html"><i class="fa fa-circle-o"></i> Blank Page</a></li>
      </ul>
    </li>
  </ul>
</section>

0 个答案:

没有答案