Php 这三个功能是如何协同工作的?

Php 这三个功能是如何协同工作的?,php,Php,我正在阅读一本php书籍,但不了解一些函数 具体来说,公共功能显示菜单($按钮)。我知道这会为菜单(主页、联系人等)创建一个表格,并将它们隔开。这里的参数是什么 public function DisplayButton($width, $name, $url, $active = true) $width = 100/count($buttons); Here is what I am not understanding. Im setting a variable called

我正在阅读一本php书籍,但不了解一些函数

具体来说,公共功能显示菜单($按钮)。我知道这会为菜单(主页、联系人等)创建一个表格,并将它们隔开。这里的参数是什么

 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));
我知道他们在屏幕上制作什么,但不了解这些功能的关键部分。有人能发出一点点光吗

//声明的变量

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>";
    }  
  }
public$content;
公共$title=‘TLA咨询私人有限公司’;
public$keywords='TLA Consulting,三个字母缩写,
我的一些好朋友是搜索引擎;
public$buttons=数组('Home'=>'Home.php',
'Contact'=>'Contact.php',
'Services'=>'Services.php',
“站点地图”=>“Map.php”
);
//类页面的操作
公共函数集($name,$value)
{
$this->$name=$value;
}
公共功能显示菜单($按钮)
{

echo“这可能缺少
声明,但我们继续

下面是声明类属性的位置

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'
                  );
\uuu set()
是PHP中的一个神奇方法。您可以稍后检查所有这些方法。我们将重点讨论
\uu set()
。这意味着每次在对象中设置属性时,它都会定义和设置此属性,即使您尚未在类中声明它

// class Page's operations
public function __set($name, $value)
{
    $this->$name = $value;
}
接下来,我们有
DisplayMenu
,它在屏幕上呈现菜单。
$width
表示每个按钮的宽度。因此,如果在
$buttons
中有4个按钮,它将分割空间,在这种情况下,空间是100%,因此,每个按钮的空间占25%

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 will render the button on screen.
        // Params:
        // 1 The width of the button.
        // 2 The name of the button.
        // 3 The url the button points to.
        // 4 Checks if the button url is the same url of the current page. 
        $this->DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
     }
     echo "  </tr>\n";
     echo "</table>\n";
}
最后,
DisplayButton
将呈现实际的按钮。每个按钮都单独呈现

public function DisplayButton($width, $name, $url, $active = true)
{
    // This will, in practice verify for you if 
    // the current page is the same of the button the user clicked. 
    // If it is, it will display the button without the link for that 
    // button, or with a disabled link. 
    // You'll notice it will show differently. Maybe 
    // also with some different color or style according to the CSS class.
    // Remember that $active is the result of the IsURLCurrentPage().

    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>";
    }  
}  
公共函数显示按钮($width、$name、$url、$active=true)
{
//这将在实践中为您验证
//当前页面与用户单击的按钮相同。
//如果是,它将显示没有该链接的按钮
//按钮,或带有禁用的链接。
//你会注意到它的表现会有所不同。也许吧
//也可以根据CSS类使用不同的颜色或样式。
//请记住,$active是IsURLCurrentPage()的结果。
如果($active)
{
回声“
";
}  
其他的
{
回声“
$name”;
}  
}  

这可能缺少
类的声明,但我们继续

下面是声明类属性的位置

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'
                  );
\uuu set()
是PHP中的一个神奇方法。您可以稍后检查所有这些方法。我们将重点讨论
\uu set()
。这意味着每次在对象中设置属性时,它都会定义和设置此属性,即使您尚未在类中声明它

// class Page's operations
public function __set($name, $value)
{
    $this->$name = $value;
}
接下来,我们有
DisplayMenu
,它在屏幕上呈现菜单。
$width
表示每个按钮的宽度。因此,如果在
$buttons
中有4个按钮,它将分割空间,在这种情况下,空间是100%,因此,每个按钮的空间占25%

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 will render the button on screen.
        // Params:
        // 1 The width of the button.
        // 2 The name of the button.
        // 3 The url the button points to.
        // 4 Checks if the button url is the same url of the current page. 
        $this->DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
     }
     echo "  </tr>\n";
     echo "</table>\n";
}
最后,
DisplayButton
将呈现实际的按钮。每个按钮都单独呈现

public function DisplayButton($width, $name, $url, $active = true)
{
    // This will, in practice verify for you if 
    // the current page is the same of the button the user clicked. 
    // If it is, it will display the button without the link for that 
    // button, or with a disabled link. 
    // You'll notice it will show differently. Maybe 
    // also with some different color or style according to the CSS class.
    // Remember that $active is the result of the IsURLCurrentPage().

    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>";
    }  
}  
公共函数显示按钮($width、$name、$url、$active=true)
{
//这将在实践中为您验证
//当前页面与用户单击的按钮相同。
//如果是,它将显示没有该链接的按钮
//按钮,或带有禁用的链接。
//你会注意到它的表现会有所不同。也许吧
//也可以根据CSS类使用不同的颜色或样式。
//请记住,$active是IsURLCurrentPage()的结果。
如果($active)
{
回声“
";
}  
其他的
{
回声“
$name”;
}  
}  

它根据按钮的数量以%为单位设置表格单元格的宽度。因此,如果您有4个按钮,则一行中的每个单元格的宽度将为25%。噢,多谢您对$this->DisplayButton($width,$name,$url,!$this->IsURLCurrentPage($url))的内容有何了解;实际上是这样吗?它创建一个
$width
%宽的表格单元格和一个带有图像的“按钮”。如果找不到图像,图像将显示
$name
文本,并且
$name
也将在“按钮”中显示为文本。带有的“按钮”具有指向
$url
!$this->IsURLCurrentPage($url)的链接
意味着有当前页面链接的按钮将没有链接,或者只是意味着有当前页面链接的按钮将被禁用。它根据按钮的数量以%为单位设置表格单元格宽度。因此,如果您有4个按钮,一行中的每个单元格都将有25%的宽度。噢,多谢了,知道$this->Display是什么吗按钮($width、$name、$url、!$this->IsURLCurrentPage($url));实际上是这样吗?它创建一个
$width
%宽的表格单元格和一个带有图像的“按钮”。如果找不到图像,图像将显示
$name
文本,并且
$name
也将在“按钮”中显示为文本。带有的“按钮”具有指向
$url
!$this->IsURLCurrentPage($url)的链接
意味着有当前页面链接的按钮将没有链接,或者只是意味着有当前页面链接的按钮将被禁用。谢谢我爱你,也是因为我是当前的,这也是允许我显示我的页面的原因吗?比如,如果我创建了一个名为contact.php的新文件,这是允许联系人可点击和o是否转到新页面?
isURLCurrentPage
将检查用户所在的当前页面是否与正在呈现的按钮所在的页面相同。如果为真,则将禁用按钮。如果不是同一页面,则将使按钮可单击,使您能够转到另一页面