Menu - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Menu (/showthread.php?tid=31419) |
Menu - El Forum - 06-18-2010 [eluser]Unknown[/eluser] I`ve done menu such way: Controller: function index(){ $data['title'] = "title"; $data['navlist'] = $this->mpttree->GetCategoryArray(); $this -> load -> vars($data); $this -> load -> view('template'); } Model: function GetCategoryArray(){ $this->set_opts(array( 'table' => 'wiki_tree', 'left' => 'lft', 'right' => 'rgt', 'id' => 'id', 'title' => 'title', 'alias' => 'alias')); // Function gets a list of all categories in the category table // and returns them as an associative array $this->db->select('node.title, (COUNT(parent.title) - 1) AS Depth, node.id, node.alias'); $this->db->from('wiki_tree AS node, wiki_tree AS parent'); $Where = "node.lft BETWEEN parent.lft AND parent.rgt AND node.lft != 1"; $this->db->where($Where); $this->db->group_by('node.title'); $this->db->order_by('node.lft'); $Query = $this->db->get(); $i = 0; foreach($Query->result() as $row){ $data[$i]['title'] = $row->title; $data[$i]['id'] = $row->id; $data[$i]['Depth'] = $row->Depth; $data[$i]['alias'] = $row->alias; $i++; } return $data; } View: <?php foreach($navlist as $Category) { $Spacing = ''; for($i=0; $i<$Category['Depth']; $i++) { $Spacing .= " "; } //echo '<div>' . $Spacing . anchor("/category/". url_title($Category['title'], 'underscore')) .'</div>'; echo '<div>' . $Spacing . anchor($Category['alias'], $Category['title']) .'</div>'; } ?> What are you thinkink about this solution? |