I am trying to make a dynamic menu, but I keep getting the fatal error. Here is the code:
class Menu {
public $menu;
function __contstruct() {
$this -> menu = array("Home" => "index.php",
//"Eat" => array("Casual" => "casual.php", "Fine dining" => "fine_dining.php"),
"Contact" => "contact.php");
}
public static function page_name() {
return substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1);
}
public static function menu_list() {
$menu_list = "";
foreach ($this->menu as $name => $url) {
echo "<li ";
if ($url == $this -> pagename()) {
$menu_list .= "class='active'";
}
$menu_list .= "><a href='";
$menu_list .= $url;
$menu_list .= "'>" . $name . "</a></li>";
return ($menu_list);
}
}
}
?>
and calling it with
$nav = new Menu();
echo $nav->menu_list();
Please help me figure why it isn't working.
$this->pagename()does not exist. you've got$this->page_name()defined.__contstruct()<= look closely. Zoom in if you have to. Better yet, look inside a dictionary.