让我让它变得简单明了:
可能和其他人一样,我在服务器上使用简单的包含来处理各种事情,例如顶部菜单或侧面菜单等等......
这是我的代码示例
<?php $number = 1; include("/var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php");?>
$number =1 像往常一样根据页面级别定义选项卡的正确选择。
我包含的代码如下:
18 <?php $page[$number] = 'selected';?>
19 <!--=================== top navigation ==================-->
20 <nav>
21 <div id="menu">
22 <a href="/Page 1/" class="tab <?php echo $page[1] ?>" title="Page 1">Page 1</a>
23 <a href="/Page 2/" class="tab <?php echo $page[2] ?>" title="Page 2">Page 2</a>
24 <a href="/Page 3/" class="tab <?php echo $page[3] ?>" title="Page 3">Page 3</a>
25 <a href="/Page 4/" class="tab <?php echo $page[4] ?>" title="Page 4">Page 4</a>
26 <a href="/Page 5/" class="tab <?php echo $page[5] ?>" title="Page 5">Page 5</a>
27 <a href="/Page 6/" class="tab <?php echo $page[6] ?>" title="Page 6">Page 6</a>
28 <a href="/Page 3/" class="tab <?php echo $page[7] ?>" title="Page 7">Page 7</a>
29 </div><!-- end .menu -->
30 </nav><!-- end .navigation -->
显然 .selected 的 css 会改变背景颜色以显示您在该特定页面上,因此无需解释。
现在的问题是,我刚刚检查了我的错误日志,该日志恰好下载得很大,并发现了以下错误:
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 2 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 23
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 3 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 24
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 4 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 25
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 5 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 26
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 6 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 27
[Sat Nov 24 17:50:50 2012] [error] [client 204.11.33.59] PHP Notice: Undefined offset: 7 in /var/www/vhosts/MyWebSite.com/httpdocs/trial/includes/header.php on line 28
我无法理解它的原因。IMO 如果 $number 已经预定义,为什么会出错?
请帮助我以正确的方式做到这一点。