 <!-- Sidebar -->
 <ul class="navbar-nav sidebar sidebar-dark accordion sidebar-custum" id="accordionSidebar">

   <!-- Sidebar - Brand -->
   <a class="sidebar-brand d-flex align-items-center justify-content-center" href="<?= base_url('Akun') ?>">
     <div class="sidebar-brand-icon rotate-n-11">
       <img src="<?=base_url('assets/img/logo/logo.png')?>" alt="">
     </div>
     <div class="sidebar-brand-text mx-3">
     </div>
   </a>

   <!-- Divider -->
   <hr class="sidebar-divider">

   <?php
    $role_id = $this->session->userdata('roles_user'); 
    $query = "SELECT `user_menu`.`id`,`menu`
              FROM   `user_menu` JOIN `user_access_menu`
              ON     `user_menu`.`id`=`user_access_menu`.`menu_id`
              WHERE  `user_access_menu`.`role_id`= $role_id 
              ORDER BY `user_access_menu`.`menu_id` ASC 
    ";

    $menu = $this->db->query($query)->result_array();

    ?>

  <?php foreach ($menu as $m) : ?>
      <li class="nav-item">
          <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#<?= $m['menu']; ?>" aria-expanded="true" aria-controls="<?= $m['menu']; ?>">
          <i class="fas fa-angle-double-right"></i>
            <span> <?= $m['menu']; ?></span>
          </a>
          <div id="<?= $m['menu']; ?>" class="collapse" aria-labelledby="heading<?= $m['menu']; ?>" data-parent="#accordionSidebar">

            <div class="bg-white py-2 collapse-inner rounded">
              <!-- kita looping sub menu -->
                    <!-- query sub menu -->

                    <?php
                      $menu_id = $m['id'];
                      $querySubMenu = "SELECT *
                                    FROM `user_sub_menu` JOIN `user_menu`
                                    ON    `user_sub_menu`.`menu_id`=`user_menu`.`id`
                                    WHERE `user_sub_menu`.`menu_id`= $menu_id
                                    AND  `user_sub_menu`.`is_active`=1
                     ";
                      $submenu = $this->db->query($querySubMenu)->result_array()

                    ?>
              <h6 class="collapse-header"><?= $m['menu']; ?> :</h6>
                  <?php
                  foreach ($submenu as $sm) :
                  ?>
                  <?php if ($title == $sm['title']) : ?>
                  <a class="collapse-item active" href="<?= base_url($sm['url'])?>">
                  <?php else : ?>
                    <a class="collapse-item" href="<?= base_url($sm['url'])?>">
                  <?php endif ?>
                  <i class="<?= $sm['icon'] ?>"></i> <?= $sm['title'] ?>
                  </a>
                 <?php endforeach ?>
            
              <!-- !end looping sub menu -->
            </div>
          </div>
      </li>
      <hr class="sidebar-divider">

  <?php endforeach ?>

   <!-- Heading -->

     <li class="nav-item">
       <a class="nav-link" href="#" data-toggle="modal" data-target="#logoutModal">
         <i class="fas fa-fw fa-sign-out-alt"></i>
         <span>logout</span></a>
     </li>
     <hr class="sidebar-divider">


     <!-- Sidebar Toggler (Sidebar) -->
     <div class="text-center d-none d-md-inline">
       <button class="rounded-circle border-0" id="sidebarToggle"></button>
     </div>

 </ul>
 <!-- End of Sidebar -->