0% found this document useful (0 votes)
798 views2 pages

Menu Dinamis Framework CI + Template adminLTE + Mysql

The document describes how to create a dynamic menu in a CodeIgniter application. It involves: 1. Creating a database table to store menu items and their properties. 2. Inserting initial menu items into the table, including a top-level item and sub-menu item. 3. Modifying the sidebar view to dynamically output menu items from the database table, including sub-menus. 4. The dynamic menu can then be viewed on the website after loading it.

Uploaded by

Jalem Putro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
798 views2 pages

Menu Dinamis Framework CI + Template adminLTE + Mysql

The document describes how to create a dynamic menu in a CodeIgniter application. It involves: 1. Creating a database table to store menu items and their properties. 2. Inserting initial menu items into the table, including a top-level item and sub-menu item. 3. Modifying the sidebar view to dynamically output menu items from the database table, including sub-menus. 4. The dynamic menu can then be viewed on the website after loading it.

Uploaded by

Jalem Putro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like