Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Menu Multilivello Smarty

    Ciao a tutti,
    stò cercando di apportare delle modifiche su un codice php per rendere il menu con infiniti submenù la parte amministrativa sono riuscita a strutturarla è funziona il problema adesso viene sullo sviluppo della parte pubblica in quanto utilizzo smarty.
    La funzione originale del codice è la seguente:

    Codice PHP:
    function smarty_function_menu ($params$smarty) {
        if (!isset(
    $params['name'])) {
            return 
    'The {menu} template plugin requires a "name" parameter to identify the menu to load.';
        }

        
    $smarty->CI->load->model('menu_manager/menu_model');
        
    $menu $smarty->CI->menu_model->get_menu_by_name($params['name']);
        
        if (empty(
    $menu)) {
            return 
    'The "name" parameter you passed to {menu} (' $params['name'] . ') is not associated with a menu.  Menu load failed.';
        }
        
        
    // set default parameter for show_sub_menus
        
    if (!isset($params['show_sub_menus'])) {
            
    $params['show_sub_menus'] = 'yes';
        }
        
        
    // we have the menu
        // get root level menu items
        
    $links $smarty->CI->menu_model->get_links(array('menu' => $menu['id'], 'parent' => '0'));
        
        if (empty(
    $links)) {
            return 
    'There are no links in this menu (' $menu['name'] . ').  Go to your Menu Manager in the control panel and add more links.';
        }
        
        
    // we'll store menu_items here with main key "id" and keys "text", "url", "active", "class"
        
    $menu_items = array();
        
    $menu_children = array();
        
        
    // parse parent links, which will in turn call child links if necessary
        
    parse_links($menu_items$menu_children$links$menu$smarty$params);
        
        
    // sort through menu items and display the menu
        
    $params['class'] = (isset($params['class'])) ? $params['class'] : '';
        
    $params['id'] = (isset($params['id'])) ? $params['id'] : '';
        
        
    $return '<ul class="' $params['class'] . '" id="' $params['id'] . '">';
        
    //
        
    foreach ($menu_items as $id => $item) {
            
    // do we have children?
            
    $children_items = array();
            
            if (
    $item['is_child'] == FALSE) {
                if (isset(
    $menu_children[$id])) {
                    foreach (
    $menu_children[$id] as $key) { 
             
                 
    $item_child $menu_items[$key];
                        
                        if (!empty(
    $menu_items[$key])) {
                            
    // set parent active if it's child is active
                            
    if ($item_child['active'] == TRUE) {
                                
    //$item['active'] = TRUE;
                            
    }
                            
                            
    $children_items[] = li_html($item_child);
                        }
                    }
                }
            }
            
            if (
    $item['is_child'] == FALSE) {
                
    $classes = (!empty($children_items)) ? array('current') : array();
                
                
    $return .= li_html($item$children_items$classes);
            }    
         
             
        }
        
        
    $return .= '[/list]';
        return 
    $return;

    Ho provato ad appartare la seguente modifica:

    Codice PHP:
    function smarty_function_menu ($params$smarty) {
        
    // check params
        
    if (!isset($params['name'])) {
            return 
    'The {menu} template plugin requires a "name" parameter to identify the menu to load.';
        }

        
    $smarty->CI->load->model('menu_manager/menu_model');
        
    $menu $smarty->CI->menu_model->get_menu_by_name($params['name']);
        
        if (empty(
    $menu)) {
            return 
    'The "name" parameter you passed to {menu} (' $params['name'] . ') is not associated with a menu.  Menu load failed.';
        }
        
        
    // set default parameter for show_sub_menus
        
    if (!isset($params['show_sub_menus'])) {
            
    $params['show_sub_menus'] = 'yes';
        }
        
        
    // we have the menu
        // get root level menu items
        
    $links $smarty->CI->menu_model->get_links(array('menu' => $menu['id'], 'parent' => '0'));
        
        if (empty(
    $links)) {
            return 
    'There are no links in this menu (' $menu['name'] . ').  Go to your Menu Manager in the control panel and add more links.';
        }
        
        
    // we'll store menu_items here with main key "id" and keys "text", "url", "active", "class"
        
    $menu_items = array();
        
    $menu_children = array();
        
        
    // parse parent links, which will in turn call child links if necessary
        
    parse_links($menu_items$menu_children$links$menu$smarty$params);
        
        
    // sort through menu items and display the menu
        
    $params['class'] = (isset($params['class'])) ? $params['class'] : '';
        
    $params['id'] = (isset($params['id'])) ? $params['id'] : '';
        
        
    $return '<ul class="' $params['class'] . '" id="' $params['id'] . '">';
        
    //
        
    foreach ($menu_items as $id => $item) {
            
    // do we have children?
            
    $children_items = array();
            
            if (
    $item['is_child'] == FALSE) {
                if (isset(
    $menu_children[$id])) {
                    foreach (
    $menu_children[$id] as $key) { 
             
                 
    $item_child $menu_items[$key];
                        
                        if (!empty(
    $menu_items[$key])) {
                            
    // set parent active if it's child is active
                            
    if ($item_child['active'] == TRUE) {
                                
    //$item['active'] = TRUE;
                            
    }
                            
                            
    $children_items[] = li_html($item_child);
                        }
                    }
                }
            }
            
            if (
    $item['is_child'] == FALSE) {
                
    $classes = (!empty($children_items)) ? array('current') : array();
                
                
    $return .= li_html($item$children_items$classes);
            }
         
    /* CLONATE PART FOR MENU LEVEL */
         
    $links2 $smarty->CI->menu_model->get_links(array('menu' => $menu['id'], 'parent' => $key));
      
    $menu_items2 = array();
        
    $menu_children2 = array();
        
    // parse parent links, which will in turn call child links if necessary
         
    parse_links($menu_items2$menu_children2$links2$menu$smarty$params);   

        foreach (
    $menu_items2 as $id2 => $item2) {   
        
    $children_items2 = array();
               if (
    $item2['is_child'] == FALSE) {
            if (isset(
    $menu_children2[$id])) {
                    foreach (
    $menu_children2[$id] as $key2) { 
             
                 
    $item_child2 $menu_items2[$key2];
                        
                        if (!empty(
    $menu_items2[$key2])) {
                            
    // set parent active if it's child is active
                            
    if ($item_child2['active'] == TRUE) {
                                
    //$item['active'] = TRUE;
                            
    }
                            
                            
    $children_items[] = li_html($item_child2);
                        }
                    }
                }
            
              }
              if (
    $item2['is_child'] == FALSE) {
                
    $classes2 = (!empty($children_items2)) ? array('current') : array();
                
                
    $return .= li_html($item2$children_items2$classes2);
            }    
           }
             
    /* ENDCLONATE PART FOR MENU LEVEL */ 
        
    }
        
        
    $return .= '[/list]';
        return 
    $return;

    Soltanto che mi limita il dump ad un solo livello e non mi visualizza in serie il 3 menù
    Qualcuno di voi sa darmi un idea oppure aiutarmi sulla modifica del seguente codice in modo tale che i menù (sub) siano recursivi?
    Grazie
    Marko

  2. #2
    ufffffffffffff non riesco proprio

  3. #3

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.