网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
06月06日漏签0天
php吧 关注:280,648贴子:1,320,735
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 16回复贴,共1页
<<返回php吧
>0< 加载中...

前面定义了public变量,后面调用时却说无此变量

  • 只看楼主
  • 收藏

  • 回复
  • MELISAWQ
  • 面向对象
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
如题!本人新学习PHP,前面定义了$buttons变量,到 public function DisplayMenu()里面需要调用时提示Notice: Undefined variable: buttons ,求大神解答!代码如下,谢谢
<?php
class page
{
public $content;
public $title = "TLA Consulting Pty Ltd ";
public $keywords = "TLA Consulting, Three Letter Abbreviation,
some of my best friends are search engines";
public $buttons = array("Home" => "home.php",
"Contact" => "Contact.php",
"Services" => "Services.php",
"Site Map" => "map.php"
);
public function __set($name, $value)
{
$this->$name = $value;
}
public function Display()
{
echo "<html>\n<head>\n";
$this->DisplayTitle();
$this->DisplayKeywords();
$this->DisplayStyles();
echo "</head>\n<body>\n";
$this->DisplayHeader();
$this->DisplayMenu($this->buttons);
echo $this->content;
$this->DisplayFooter();
echo "</body>\n</html>\n";
}
public function DisplayTitle()
{
echo "<title>".$this->title."</title>";
}
public function DisplayKeywords()
{
echo "<meta name=\"keywords\"
content=\"".$this->keywords."\"/>";
}
public function DisplayStyles()
{
?>
<style>
h1 {
color: white;
font-size: 24pt;
text-align: center;
font-family: arial, sans-serif
}
.menu {
color: white;
font-size: 12pt;
text-align: center;
font-family: arial, sans-serif;
font-weight: bold
}
td {
background: black
}
p {
color: black;
font-size: 12pt;
text-align: justify;
font-family: arial, sans-serif
}
p.foot {
color: white;
font-size: 9pt;
text-align: center;
font-family: arial, sans-serif;
font-weight: bold
}
a:link, a:visited, a:active {
color: white
}
</style>
<?php
}
public function DisplayHeader()
{
?>
<table width="100%" cellpadding="12"
cellspacing="0" border="0">
<tr bgcolor="black">
<td align="left"><img src="logo.gif"/></td>
<td>
<h1>TLA Consulting Pty Ltd</h1>
</td>
<td align="right"><img src="logo.gif"/></td>
</tr>
</table>
<?php
}
public function DisplayMenu()
{
echo "<table width=\"100%\" bgcolor=\"white\"
cellpadding=\"4\" cellspacing=\"4\">\n";
echo "<tr>\n";
$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>";
}
}
public function DisplayFooter()
{
?>
<table width="100%" bgcolor="black" cellpadding="12" border="0">
<tr>
<td>
<p class="foot">&copy; TLA Consulting Pty Ltd.</p>
<p class="foot">Please see our <a href ="">legal inmation page</a></p>
</td>
</tr>
</table>
<?php
}
}
?>


  • MELISAWQ
  • 面向对象
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
大婶们都睡了么


2025-06-06 05:23:13
广告
  • 尼玛吃团子
  • 面向对象
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
加$this 试试


  • lolly
  • 变魔术
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
$this->buttons


  • MELISAWQ
  • 面向对象
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
睡不着觉,明天还要上班,好难过


  • MELISAWQ
  • 面向对象
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
早起一顶


  • wsxmsx
  • 框架好玩
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
多代码,我建议直接贴图,


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 16回复贴,共1页
<<返回php吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示