1
Hello!
I’m using the menu helper to include class active
in the menus of the site.
Helper Menu:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
if(!function_exists('active_link'))
{
function menu_ativo($controller)
{
//Obtem Instância da classe CI
$CI = get_instance();
//Obtem classe ativa.
$class = $CI->router->fetch_class();
return ($class == $controller) ? 'active' : '';
}
}
?>
And I invoke this function as below
<li class="treeview <?php echo menu_ativo('conta'); ?>">
<a href="#">
<i class="fa fa-money"></i>
<span><?php echo 'Financeiro'; ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li class="<?php echo menu_ativo('categoria'); ?>">
<a href="<?php echo site_url('app/categoria'); ?>"><i class="fa fa-circle-o"></i>Categoria</a>
</li>
<li class="<?php echo menu_ativo('conta'); ?>">
<a href="<?php echo site_url('app/conta'); ?>"><i class="fa fa-circle-o"></i>Conta</a>
</li>
<li class="<?php echo menu_ativo('encargo'); ?>">
<a href="<?php echo site_url('app/encargo'); ?>"><i class="fa fa-circle-o"></i>Encargo</a>
</li>
<li class="<?php echo menu_ativo('lancamento'); ?>">
<a href="<?php echo site_url('app/lancamento'); ?>"><i class="fa fa-circle-o"></i>Lançamento</a>
</li>
</ul>
</li>
My problem is basically in <li class="treeview <?php echo " ???? " ;?>">
Since each <li>
inside <ul>
belongs to a different controller, I want to activate any sub-menu and keep the main-menu active <li>
.
However with the helper above it is not working, although the submenu is inheriting the class active
, the main menu is closing.
Can you direct me ?
It worked this way:
Edit: Em caso de ser submenu, você pode fazer uma validação entre os módulos, if($this->uri->segment(1)=='categoria' or $this->uri->segment(1)=='categoriaB' or $this->uri->segment(1)=='categoriaC') echo "active";
Thank you.– Wagner Fillio