2016-08-26 2 views
-1

Привет всем Я хочу создать верхнюю навигацию в воспламенителе кода. Как я могу создать его. Я использовал много примеров, но ни один из них не является правильным.Навигация N-уровня в codeignitor

Пожалуйста, помогите мне Спасибо заранее

ответ

0

В контроллере я должен объявить функции и вызов модели

private function getNavigation(){ 
    $this->load->model('xx'); 
    $data['nav'] = $this->xx->prepareTree(); 
    $this->load->view('index',$data); 
} 

И В модели у меня есть объявить три функции

public function prepareTree(){ 
    $this->db->select("`catalog_parent` as parent_id, `catalog_name` as menu_item, `catalog_id` as id, `catalog_template` as pager_id"); 
    $this->db->from("catalog_category"); 
    $this->db->where("`catalog_navigation` = '1'"); 
    $this->q = $this->db->get(); 
    $create = ''; 
    if ($this->q->num_rows() > 0) { 
     $create = $this->prepareList($this->q->result_array()); 
    } 
    if(!empty($create)){ 
     return $this->category_tree($create); 
    } else { 
     return ''; 
    } 
} 

private function prepareList(array $items, $pid = 0) { 
    $output = array(); 
    foreach ($items as $item) { 
     if ((int) $item['parent_id'] == $pid) { 
      if ($children = $this->prepareList($items, $item['id'])) { 
       $item['children'] = $children; 
      } 
      $output[] = $item; 
     } 
    } 
    return $output; 
} 

private function category_tree($menu_items, $child = false){ 
    $output = ''; 
    if (count($menu_items)>0) { 
     $output .= ($child === false) ? '<ul id="main-menu" class="sm sm-blue">' : '<ul>' ; 

     foreach ($menu_items as $item) { 
      $output .= '<li>'; 
      $output .= '<a href="#">'.$item['menu_item'].'</a>'; 
      if (isset($item['children']) && count($item['children'])) { 
       $output .= $this->category_tree($item['children'], true); 
      } 
      $output .= '</li>'; 
     } 
     $output .= '</ul>'; 
    } 
    return $output; 
} 

Если некоторые предполагают пожалуйста, предложите нам более простой способ. Thanks

Смежные вопросы