私はPHPの本をフォローしており、いくつかの機能を理解していません。これら3つの機能はどのように連携して機能していますか?
特に、public関数DisplayMenu($ buttons)。私はこれがメニュー(家、連絡先などのためのテーブルを作成し、それらを除外する)を作成することを知っています。そして、ここでパラメータ
public function DisplayButton($width, $name, $url, $active = true)
$width = 100/count($buttons);
Here is what I am not understanding. Im setting a variable called width to be 100/count ? lets say buttons are 4 so 100/4 25? What is the point of the 25? Also,
$this -> DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
は、私は、彼らが画面上に作り出すか知っているが、これらのfucntiosnの重要な部分をunderstadningありません。ある人が小さな光を放つことができますか?あなたのクラス属性が宣言されている場合
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'
);
// class Page's operations
public function __set($name, $value)
{
$this->$name = $value;
}
public function DisplayMenu($buttons)
{
echo "<table width='100%' bgcolor='red' cellpadding='3'
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";
}
{
if ($active)
{
echo "<td width ='$width%'>
<a href ='$url'>
<img src ='s-logo' 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='test'>$name</span></td>";
}
}
public function IsURLCurrentPage($url)
//#determines weather a url for the button points to the current page.
// #the server[php_self,$url] returns a number if the string in $url is inside the superglobal variable $_server[pph]
{
if(strpos($_SERVER['PHP_SELF'], $url)==false)
{
return false;
}
else
{
return true;
}
}
public function DisplayButton($width, $name, $url, $active = true)
//outputs a single menu button if button is to point to the page to are on, you display an inactive button
#I think width just gives the table cell a % value. $name involves a setter function declared up top? ,
{
if ($active)
{
echo "<td width ='$width%'>
<a href ='$url'>
<img src ='s-logo' 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='test'>$name</span></td>";
}
}
ボタンの数に応じて表のセル幅を%で設定します。したがって、4つのボタンがある場合、各セルは1行に25%の幅で表示されます。 – TheDrot
おおきにありがとう/ $ this-> DisplayButton($ width、$ name、$ url、!$ this-> IsURLCurrentPage($ url));実際には? –
'$ width'%幅のテーブルセルとその中に画像を持つ 'button'を作成します。画像が見つからない場合、画像は '$ name'テキストを表示し、' button 'の中に '$ name'もテキストとして表示します。 '$ url'と '!$ this-> IsURLCurrentPage($ url)'へのリンクを持つ 'ボタン'は、現在のページへのリンクを持つボタンにはリンクがないことを意味します。現在のページへのリンクが無効になります。 – TheDrot