CodeIgniter Forums

Full Version: active drop down dynamic menu from database codeigniter 4 and adminlte 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
 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();
}