2016-06-14 90 views
0

遺憾的菜單層級白手起家我的英文不好 我有一個表菜單: here is my table menus創建PHP與MySQL

,所以我想問一下,如何使基於表中的數據代碼的過程。 或者任何人有這方面的參考?

這是我試過的代碼,但還是失敗了

public function all_tree() 
    { 
     $nodes = $this->db->get('alus_menu_group')->result(); 
     return $this->getChildren($nodes, 0, 0); 
    } 

public function getChildren($nodes ,$pid = 0, $depth = 0) 
    { 
     $tree = array(); 

     foreach($nodes as $node) { 

     if ($node->menu_parent == $pid) { 

      if($depth == 0) 
      { 
       if(!$this->getChildren1($nodes, $node->menu_id, ($depth + 1))) 
       { 
        $hasil = "<li class='dropdown'> 
         <a href='#' class='dropdown-toggle' data-toggle='dropdown'>".$node->menu_nama."</a> 
         <ul class='dropdown-menu'>"; 
        $hasil .= $this->getChildren($nodes, $node->menu_id, ($depth + 1)); 

       }else 
       { 
        $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."</a></li>";  
       } 
      } 
      if($depth == 1) 
      { 
       if(!$this->getChildren1($nodes, $node->menu_id, ($depth + 1))) 
       { 
        $hasil = "<li class='dropdown-submenu'> 
         <a href='#'>".$node->menu_nama."</a> 
         <ul class='dropdown-menu'>"; 
        $hasil .= $this->getChildren($nodes, $node->menu_id, ($depth + 1)); 

       }else 
       { 
        $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."</a></li></ul></li>";  

       } 

      }if ($depth == 2) 
      { 
       $hasil = "<li><a href=".base_url().$node->menu_uri." target=".$node->menu_target.">".$node->menu_nama."2</a></li></ul></li></ul></li>"; 

      } 
      $tree[] = $hasil; 
     } 

     } 
     return $tree; 
    } 
    public function view() 
{ 
$data['tree'] = $this->all_tree(); 
$this->load->view('index.php',$data); 
} 

那麼在view.php即時通訊做的foreach。 有人可以幫忙嗎? thnks

回答