[eluser]ramm[/eluser]
Nice!
I did what you said and it worked fine.
This is my config file: (The ids are optional)
Code:
$config['navigation'] = array(
'home' => array(
'id' => 'home',
'title' => 'Home',
'link' => ''
),
'about' => array(
'id' => 'about',
'title' => 'About Us',
'link' => 'about'
),
'contact' => array(
'title' => 'Contact Us',
'link' => 'contact'
)
);
And here is the helper code
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* menu_ul
* Returns a unordered list with the selected item as current
*/
if ( ! function_exists('menu_ul'))
{
function menu_ul($sel = 'home')
{
$CI =& get_instance();
$items = $CI->config->item('navigation');
$menu = '<ul class="main_nav">'."\n";
foreach($items as $item)
{
$current = (in_array($sel, $item)) ? ' class="current"' : '';
$id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : '';
$menu .= '<li'.$current.'><a href="'.$item['link'].'">'.$item['title'].'</a></li>'."\n";
}
$menu .= '</ul>';
return $menu;
}
}
// ------------------------------------------------------------------------
/**
* menu_p
* Returns a paragraph with the selected item as current
*/
if ( ! function_exists('menu_p'))
{
function menu_p($sel = 'home', $separator = '')
{
$CI =& get_instance();
$items = $CI->config->item('navigation');
$count = count($items);
$i = 0;
$menu = "\n".'<p class="bottom_nav">';
foreach($items as $item)
{
$current = (in_array($sel, $item)) ? ' class="current"' : '';
$id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : '';
$menu .= '<a'.$current.' href="'.$item['link'].'"'.$id.'>'.$item['title'].'</a>';
$i++;
if($count != $i)
{
$menu .= ' '.$separator.' ';
}
}
$menu .= '</p>'."\n";
return $menu;
}
}
/* End of file navigation_helper.php */
/* Location: ./system/helpers/navigation_helper.php */
Use
Code:
<?php echo menu_ul('about'); ?>
//Outputs an unordered list with the <li class="current"> for the about link
Code:
<?php echo menu_p('about', '|'); ?>
//Second parameter is separator, optional
Still not sure if i'm loading the config file correctly, but it works fine.
Thank you.