Open GoogleCodeExporter opened 9 years ago
I think you are right.
But that's why I never print menu by id. If you check the header.php in the
default template, you can see how I build menus by parent name.
So I create parent menus like "topmenu", "leftmenu" etc.
Then to get the menu structure I do
{{
$navs = $this->navigation->get(array('title' => 'topmenu', 'lang' =>
$this->user->lang))
}}
So I get the menu by title.
Maybe instead of doing twice the query (i.e. findID first then print by ID), it
is better to create a function print_menu_by_title($title)
What do you think?
Original comment by heriniai...@gmail.com
on 13 Oct 2010 at 10:16
That could easily be done. I'll work it up for you.
Original comment by rmorga...@gmail.com
on 13 Oct 2010 at 10:26
Here are the methods I worked out for named menus:
Use: echo $this->navigation->print_menu_by_title('Footer-Menu');
Code (Add to the Navigation library):
function print_menu_by_title($title='')
{
//echo "Parent Id: ".$parent;
if (!$data = $this->obj->cache->get('navigation'.$title.$this->obj->user->lang, 'navigation'))
{
$data = $this->_print_menu_by_title($title);
$this->obj->cache->save('navigation'.$title.$this->obj->user->lang, $data, 'navigation',0 );
}
return $data;
}
function _print_menu_by_title($title='')
{
$select = "SELECT t1.* "
."FROM `ci_navigation` t1 "
."JOIN `ci_navigation` t2 ON t1.parent_id = t2.id "
."WHERE t2.title = '$title '"
."AND t1.active = 1 "
."AND t2.lang = '".$this->obj->user->lang."' "
."AND t1.lang = '".$this->obj->user->lang."' "
."AND t2.g_id IN ('".join("', '", $this->obj->user->groups)."') "
."AND t1.g_id IN ('".join("', '", $this->obj->user->groups)."') "
."ORDER BY t1.parent_id, t1.weight";
$query = $this->obj->db->query($select);
if ($query->num_rows() == 0)
{
return false;
}
$html = '<ul ' . (($this->nav_opened == false) ? 'class="nav"' : '') . '>';
$this->nav_opened = true;
foreach ($query->result_array() as $item)
{
$html .= '<li ' . ($item['uri'] == substr($this->obj->uri->uri_string(), 1) ? 'class="current" ' : '') . '>';
$html .= '<a href="'. $this->fix_uri($item['uri']) .'">'.$item['title'].'</a>';
// calling same function where we are (recursive) to check if menu item has submenu
$html .= $this->_print_menu($item['id']);
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
Original comment by rmorga...@gmail.com
on 13 Oct 2010 at 11:38
Here are the methods I worked out for named menus:
Use: echo $this->navigation->print_menu_by_title('Footer-Menu');
Code (Add to the Navigation library):
function print_menu_by_title($title='')
{
//echo "Parent Id: ".$parent;
if (!$data = $this->obj->cache->get('navigation'.$title.$this->obj->user->lang, 'navigation'))
{
$data = $this->_print_menu_by_title($title);
$this->obj->cache->save('navigation'.$title.$this->obj->user->lang, $data, 'navigation',0 );
}
return $data;
}
function _print_menu_by_title($title='')
{
$select = "SELECT t1.* "
."FROM `ci_navigation` t1 "
."JOIN `ci_navigation` t2 ON t1.parent_id = t2.id "
."WHERE t2.title = '$title '"
."AND t1.active = 1 "
."AND t2.lang = '".$this->obj->user->lang."' "
."AND t1.lang = '".$this->obj->user->lang."' "
."AND t2.g_id IN ('".join("', '", $this->obj->user->groups)."') "
."AND t1.g_id IN ('".join("', '", $this->obj->user->groups)."') "
."ORDER BY t1.parent_id, t1.weight";
$query = $this->obj->db->query($select);
if ($query->num_rows() == 0)
{
return false;
}
$html = '<ul ' . (($this->nav_opened == false) ? 'class="nav"' : '') . '>';
$this->nav_opened = true;
foreach ($query->result_array() as $item)
{
$html .= '<li ' . ($item['uri'] == substr($this->obj->uri->uri_string(), 1) ? 'class="current" ' : '') . '>';
$html .= '<a href="'. $this->fix_uri($item['uri']) .'">'.$item['title'].'</a>';
// calling same function where we are (recursive) to check if menu item has submenu
$html .= $this->_print_menu($item['id']);
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
Original comment by rmorga...@gmail.com
on 13 Oct 2010 at 11:42
Original issue reported on code.google.com by
rmorga...@gmail.com
on 13 Oct 2010 at 10:06