这是一个创建于 4049 天前的主题,其中的信息可能已经有所发展或是发生改变。
这么写的人是个什么心态。。。 !$this->IsURLCurrentPage($url)和active=true,看得好纠结。。。
public function DisplayMenu($buttons)
{
echo "<table width=\"100%\" bgcolor=\"white\"
cellpadding=\"4\" cellspacing=\"4\">\n";
echo "<tr>\n";
//calculate button size
$width = 100/count($buttons);
while (list($name, $url) = each($buttons)) {
$this -> DisplayButton($width, $name, $url,
!$this->IsURLCurrentPage($url));
}
echo "</tr>\n";
echo "</table>\n";
}
public function IsURLCurrentPage($url)
{
if(strpos($_SERVER['PHP_SELF'], $url )==false)
{
return false;
}
else
{
return true;
}
}
public function
DisplayButton($width,$name,$url,$active = true)
{
if ($active) {
echo "<td width = \"".$width."%\">
<a href=\"".$url."\">
<img src=\"s-logo.gif\" alt=\"".$name."\" border=\"0\" /></a>
<a href=\"".$url."\"><span class=\"menu\">".$name."</span></a>
</td>";
} else {
echo "<td width=\"".$width."%\">
<img src=\"side-logo.gif\">
<span class=\"menu\">".$name."</span>
</td>";
}
}
第 1 条附言 · 2013-09-01 02:55:09 +08:00
这是PHP and MySQL web development第四版的例子,马上就要出版第五版了
13 条回复 • 1970-01-01 08:00:00 +08:00
|
|
1
mantianyu 2013-08-31 21:36:24 +08:00
珍爱生命,远离框架
|
|
|
2
yakczh 2013-08-31 21:52:21 +08:00
还停留在服务端拼字符串的阶段,现在已经是angularjs,react的时代
|
|
|
3
raincious 2013-08-31 21:54:02 +08:00
这代码应该很老了吧?
while (list($name, $url) = each($buttons));
怎么不写成foreach($buttons AS $key => $val)?
看似目的就是为了平均的产生按钮。
但是,这样组织代码也太悲剧了。上Smarty吧至少。。。
|
|
|
4
Golevka 2013-09-01 02:39:06 +08:00
我感觉那一坨字符串拼接才是最反人类的
|
|
|
5
yopming 2013-09-01 09:40:17 +08:00
拼接HTML代码是很不友好的,不使用模板引擎非常不利于协作分离
|
|
|
6
darasion 2013-09-01 11:08:25 +08:00 1
看 php 的书,都不如看手册。
|
|
|
7
hanf 2013-09-03 09:53:16 +08:00
php程序员真悲催啊~~
|
|
|
8
zhouitpro 2013-09-03 15:14:09 +08:00
应该是个老程序员
|
|
|
9
msg7086 2013-09-03 21:24:12 +08:00
IsURLCurrentPage里的代码简直是鬼斧神工
|
|
|
11
sharpnk 2013-09-03 23:37:14 +08:00
@ kennedy32 return strpos($_SERVER['PHP_SELF'], $url );
|
|
|
13
gaody 2013-09-04 15:00:32 +08:00
@ msg7086 返回0 啊啊啊啊啊,我疯了,不要管我
|