CodeIgniter Forums
active drop down dynamic menu from database codeigniter 4 and adminlte 3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: active drop down dynamic menu from database codeigniter 4 and adminlte 3 (/thread-77504.html)



active drop down dynamic menu from database codeigniter 4 and adminlte 3 - tataq17 - 09-08-2020

 created application with codeigniter 4 and adminlte 3, I've problem with active dropdown sidebar dynamic menu from database, when menu is clicked drop down menu not open, but menu inside dropdown is active. how to make dropdown menu is always open menu when menu inside there is active. here's my code:

Code:
   <?php $menu = amenu(); //helper access
        $request = \Config\Services::request();
        $uri = $request->uri;
        foreach ($menu as $a) : ?>
          <?php $submenu = aSubMenu($a['menu_id']); //helper access
          if ($submenu) : ?>
            <li class="nav-item has-treeview <?= $uri->getPath() == $a['menu_name'] ? 'menu-open' : '' ?>">
              <a href=" <?= $a['menu_name']; ?>" class="nav-link">
                <i class="nav-icon <?= $a['menu_icon']; ?>"></i>
                <p>
                  <?= $a['menu_name']; ?>
                  <i class="right fas fa-angle-left"></i>
                </p>
              </a>
              <ul class="nav nav-treeview">
                <?php foreach ($submenu as $sm) : ?>
                  <li class="nav-item">
                    <a href="<?= $sm['sm_url']; ?>" class="nav-link <?= $sm['sm_title'] == $title ? "active" : "" ?>">
                      <i class="far fa-circle nav-icon"></i>
                      <p><?= $sm['sm_title']; ?></p>
                    </a>
                  </li>
                <?php endforeach; ?>
              </ul>
            </li>
          <?php else : ?>
            <li class="nav-item has-treeview ">
              <a href=" <?= $a['menu_url']; ?>" class="nav-link <?= $a['menu_name'] == $title ? "active" : "" ?>">
                <i class="nav-icon <?= $a['menu_icon']; ?>"></i>
                <p>
                  <?= $a['menu_name']; ?>
                </p>
              </a>
            <?php endif ?>
          <?php endforeach; ?>
helper

Code:
function amenu(){
$db = \Config\Database::connect();
$session = \Config\Services::session();
$role = $session->get('users_role_id');
$query = "SELECT `menu_id`,`menu_name`,`menu_url`,`menu_icon`,`menu_is_active`
            FROM `users_menu` JOIN `users_access_menu`
            ON `users_menu`.`menu_id`=`users_access_menu`.`am_menu_id`
            WHERE `users_access_menu`.`am_role_id`= $role
            and `menu_is_active`=1
            ORDER BY `users_access_menu`.`am_menu_id` ASC";
return $db->query($query)->getResultArray();
}

function aSubMenu($sm){
$db = \Config\Database::connect();
$query = "SELECT *
            FROM `users_sub_menu`
            WHERE `sm_menu_id`= $sm and `sm_is_active`=1";
return $db->query($query)->getResultArray();
}