Welcome Guest, Not a member yet? Register   Sign In
my own helper creating menu
#19

[eluser]Krystian[/eluser]
ok, based on your previous advices

library, I used CI super object

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mymenu {
    

    public function create_menu($parent, $level)
    {
        $CI =& get_instance();
        
        $query = $CI->db->query("SELECT a.id id, a.label label, a.link link, Deriv1.Count count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);

        $menu .= "<ul id='nav'>";

          
        foreach($query->result() as $position)
        {
            if($position->count > 0) {
                
                $menu .= "<li><a >link . "'>" . $position->label . "</a>";

                    $menu .= $this->create_menu($position->id, $level + 1);

                $menu .= "</li>";
                
            }elseif($position->count == 0) {
            
                $menu .= "<li><a >link . "'>" . $position->label . "</a></li>";
                
            }else;

            }

           $menu .= "</ul>";
          
           return $menu;        
    }
}

/* End of file Mymenu.php */

then in controller
Code:
$data['menu_header'] = $this->mymenu->create_menu(0, 1);
everything works fine. Thanks!

Why I get Undefined variable: menu ( this is not a problem, but why when I code in the first line var $menu = '' I get parse error ? and when $menu = '' not? all systems libraries have got var )


Messages In This Thread
my own helper creating menu - by El Forum - 08-13-2011, 07:05 AM
my own helper creating menu - by El Forum - 08-13-2011, 10:37 AM
my own helper creating menu - by El Forum - 08-13-2011, 11:25 AM
my own helper creating menu - by El Forum - 08-13-2011, 12:04 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:10 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:14 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:23 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:42 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:51 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:17 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:33 PM
my own helper creating menu - by El Forum - 08-13-2011, 07:06 PM
my own helper creating menu - by El Forum - 08-14-2011, 02:31 AM
my own helper creating menu - by El Forum - 08-14-2011, 04:04 AM
my own helper creating menu - by El Forum - 08-14-2011, 05:53 AM
my own helper creating menu - by El Forum - 08-14-2011, 06:28 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:11 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:34 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB