Vous êtes sur la page 1sur 2

1. Melanjutkan materi 1.

2. Buat tabel :

CREATE TABLE `menu_dinamis` (


`id` int(11) NOT NULL,
`judul` varchar(50) NOT NULL,
`link` varchar(50) NOT NULL,
`icon` varchar(50) NOT NULL,
`id_menuUtama` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

3. Insert data :
INSERT INTO `menu_dinamis` VALUES (1,'Home','#','fa fa-dashboard',0);
INSERT INTO `menu_dinamis` VALUES (2,'Judul Menu 1','#','fa fa-laptop',0);
INSERT INTO `menu_dinamis` VALUES (3,'Sub Menu 1','#','fa fa-laptop',2);

4. Hapus isi script htdocs\ci_ku\application\views\template\sidebar.php , ganti dengan

<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p>Alexander Pierce</p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
</div>
</div>
<!-- search form -->
<form action="#" method="get" class="sidebar-form">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button type="submit" name="search" id="search-btn" class="btn btn-flat"><i
class="fa fa-search"></i>
</button>
</span>
</div>
</form>
<!-- /.search form -->
<!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu">
<li class="header">MAIN NAVIGATION</li>
<?php
// data main menu
$main_menu = $this->db->get_where('menu_dinamis', array('id_menuUtama'
=> 0));
foreach ($main_menu->result() as $main) {
// Query untuk mencari data sub menu
$sub_menu = $this->db->get_where('menu_dinamis', array('id_menuUtama'
=> $main->id));
// periksa apakah ada sub menu
if ($sub_menu->num_rows() > 0) {
// main menu dengan sub menu
echo "<li class='treeview'>" . anchor($main->link, '<i class="' . $main->icon
. '"></i>' . $main->judul .
'<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>');
// sub menu nya disini
echo "<ul class='treeview-menu'>";
foreach ($sub_menu->result() as $sub) {
echo "<li>" . anchor($sub->link, '<i class="' . $sub->icon . '"></i>' . $sub-
>judul) . "</li>";
}
echo"</ul></li>";
} else {
// main menu tanpa sub menu
echo "<li>" . anchor($main->link, '<i class="' . $main->icon . '"></i>' .
$main->judul) . "</li>";
}
}
?>
</section>
<!-- /.sidebar -->
</aside>

5. Buka web http://localhost/ci_ku/kontenku