I am trying to make a own class in CodeIgniter and therefore I have made a file in the folder
libraries
This class is called
Menu
And it contains a class to create a navigation bar for my website. this class is like
class Menu {
public function draw($menu) {
$CI =& get_instance();
$output = '';
foreach ($menu as $key => $value) {
$output .= "<li>";
if (is_array($value)) {
if (strpos($key, '|') !== false) {
$param = explode('|', $key);
$output .= anchor($param[1], $param[0]);
} else {
$output .= anchor('#', $key);
}
$output .= PHP_EOL."<ul>".PHP_EOL;
$output .= draw($value);
$output .= "</ul>".PHP_EOL."</li>".PHP_EOL;
} else {
$output .= anchor($key, $value, $CI->uri->slash_segment(1, 'leading') == $key ? 'class="active"' : '');
$output .= "</li>".PHP_EOL;
}
}
return $output;
}
}
I have put this class in my config file as autoload under libraries
$autoload['libraries'] = array('menu');
When I call the class to use it I do this
<?php
$m = new Menu();
echo $m->draw($menu);
?>
But unfortunately I get this error
Fatal error: Call to undefined function draw() in /Users/username/Sites/infinity2.0/application/libraries/Menu.php on line 22
Line 22 is $output .= draw($value);
But I don't know how to solve this I think its because of calling its own method again.. any help is welcome and appreciated. :)