Postingan lainnya
Codeigniter menu yamm bootstrap
mohon bantuan untuk membuat menu dengan tampilan seperti berikut: <a href='https://s11.postimg.org/abidgz11f/Screenshot_1.png '>https://s11.postimg.org/abidgz11f/Screenshot_1.png </a>
library : Menu_dropdown
class Menu_dropdown {
protected $CI;
public $menu;
function __construct(){
$this->CI =& get_instance();
}
// fungsi untuk mengambil menu
function ambil_menu($type_menu,$parent=0){
$kondisi=array(
"menu_id"=>$type_menu,
"menu_child_parent" => $parent,
"aktif" => "Y"
);
//query ke database
$this->CI->db->order_by("posisi","ASC");
$query= $this->CI->db->get_where("menu_child",$kondisi);
//cek apakah memiliki hasil
if($query->num_rows()>0){
$class=$parent==0?"nav navbar-nav":"dropdown-menu";
$this->menu.="<ul class='$class'>";
foreach ($query->result_array() as $menu) {
//cek apakah menu sekarang mempunyai submenu atau tidak
$cek=$this->CI->db->get_where("menu_child",array('menu_child_parent'=>$menu['menu_child_id'],'aktif'=>'Y','menu_id'=>$type_menu));
//jika terdapat sub menu
if($cek->num_rows()>0){
$this->menu.= "<li class='dropdown yamm-fw'><a href='$menu[menu_child_url]' target='$menu[menu_child_target]' class='dropdown-toggle' data-hover='dropdown' data-toggle='dropdown'>$menu[menu_child_nama]</a>";
//panggil ambil_menu() secara reqursive untuk mengambil sub-menu nya
$this->ambil_menu($type_menu,$menu['menu_child_id']);
$this->menu.= "</li>";
}
//jika tidak memiliki sub menu
else {
$this->menu.= "<li><a href='$menu[menu_child_url]' target='$menu[menu_child_target]'>$menu[menu_child_nama]</a>";
$this->menu.= "</li>";
}
}
$this->menu.="</ul>";
} else {
//jika tidak ada hasil.
//return;
}
}
}
Controller : AN_Controller
$this->load->library("menu_dropdown");
$this->menu_dropdown=$this->menu_dropdown->menu;
View
<div class="navbar-collapse collapse" id="mc-horizontal-menu-collapse">
<div class="nav-outer">
<?php
$menu_dropdown = new menu_dropdown;
$menu_dropdown->ambil_menu(1);
echo $menu_dropdown->menu;
?>
</div>
0