这么写的人是个什么心态。。。

2013-08-31 21:27:44 +08:00
 kennedy32
这么写的人是个什么心态。。。 !$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>";
}
}
5208 次点击
所在节点    PHP
13 条回复
mantianyu
2013-08-31 21:36:24 +08:00
珍爱生命,远离框架
yakczh
2013-08-31 21:52:21 +08:00
还停留在服务端拼字符串的阶段,现在已经是angularjs,react的时代
raincious
2013-08-31 21:54:02 +08:00
这代码应该很老了吧?

while (list($name, $url) = each($buttons));

怎么不写成foreach($buttons AS $key => $val)?

看似目的就是为了平均的产生按钮。

但是,这样组织代码也太悲剧了。上Smarty吧至少。。。
Golevka
2013-09-01 02:39:06 +08:00
我感觉那一坨字符串拼接才是最反人类的
yopming
2013-09-01 09:40:17 +08:00
拼接HTML代码是很不友好的,不使用模板引擎非常不利于协作分离
darasion
2013-09-01 11:08:25 +08:00
看 php 的书,都不如看手册。
hanf
2013-09-03 09:53:16 +08:00
php程序员真悲催啊~~
zhouitpro
2013-09-03 15:14:09 +08:00
应该是个老程序员
msg7086
2013-09-03 21:24:12 +08:00
IsURLCurrentPage里的代码简直是鬼斧神工
kennedy32
2013-09-03 23:17:58 +08:00
@msg7086 求解释?

@zhouitpro 老书
sharpnk
2013-09-03 23:37:14 +08:00
@kennedy32

return strpos($_SERVER['PHP_SELF'], $url );
msg7086
2013-09-03 23:53:21 +08:00
@sharpnk 别忘记strpos与===的著名大坑

@kennedy32 呃……这应该不用解释了吧?
gaody
2013-09-04 15:00:32 +08:00
@msg7086 返回0 啊啊啊啊啊,我疯了,不要管我

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/80890

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX