I may be using the Navigation class incorrectly. However, the only way I see to
have multiple menus in the system is to create a disabled parent and then pass
the parent id to the print_menu() method. This becomes an issue if you develop
on multiple machines as I do where the actual record id may be different from
one db to another. I develop on a local host and then move things to the
server. Unless the server db is an exact replica of the development db, the ids
don't always match.
I think it would be better if we allowed users to gain access to the menu item
id via a method call where we look up the menu item by title. That way the user
could define disabled place holders like "Top-Menu" and "Footer-Menu" and then
print the menu doing something like:
echo $this->navigation->print_menu($this->navigation->findId('Top-Menu'));
echo $this->navigation->print_menu($this->navigation->findId('Footer-Menu'));
If you like this idea the following code added to the navigation library would
do the job:
/**
* Given a menu item's title
* Or an array of field/value pairs
* Return it's record id
*/
function findId($params=array())
{
$result = 0;
// do we have an array of fields?
if(!empty($params)&& is_array($params))
{
foreach($params as $f => $v)
{
$this->obj->db->where($f, $v);
}
}
// Assume title
elseif(!empty($params) && is_string($params))
{
$this->obj->db->where('title', $params);
}
else
{
return $result;
}
// Insure we only return one record
$this->obj->db->limit(1);
$query = $this->obj->db->get('navigation');
foreach($query->result() as $row)
{
$result = $row->id;
}
return $result;
}
Finally, we could just wrap the above call in a method like:
$this->navigation->print_named_menu($title);
This way the user doesn't need to know the id.
Original issue reported on code.google.com by
rmorga...@gmail.comon 13 Oct 2010 at 10:06