所以我有两个php类,一个是类,一个用另一个,我的类是:
(菜单.php)
<?php
public class Menu
{
$home = '<li><a href="index.html"><span>Home</span></a></li>';
$home_selected = '<li class="navhome"><a href="index.html"><span>Home</span></li>';
$projects = '<li><a href=""><span>Projects</span></a></li>';
$projects_selected = '<li class="navhome"><a href=""><span>Projects</span></a></li>';
$contact = '<li><a href=""><span>Contact Us</span></a></li>';
$contact_selected = '<li class="navhome"><a href=""><span>Contact Us</span></a></li>';
public function getMyMenu($value)
{
switch($value) {
case "home":
return (string) $home_selected . $projects . $contact;
break;
case "projects":
return $home . $projects_selected . $contact;
break;
case "contact":
return $home . $projects . $contact_selected;
break;
}
}
}
?>
但是,在 index.php 中,无论何时
<?php include("menu.php");
$menu = new Menu();
echo($menu->getMyMenu("home")); ?>
或者放置任何变体,然后网页就不会加载,例如,如果它放在页面中间,页面的末尾甚至不会发送到浏览器。
我对 php 很陌生,我希望这是一个“duh”的答案,如果您需要更多,请询问;谢谢