Hi, Folks,
Trying to build a site using PHP5's OO capabilities. The main navigation, in class.Base.php, should lead to the page indicated, and that works fine when I use an instanceof Base, say $index. Some of those pages are actually the first pages in thier own sections, so there's a sub-navigation bar which should show up for each of those, so I've built class.Section1.php. Problem is, when I create an instance, say $page1, the subnav is either reflecting the visual appearance of the main one when I use it as shown, or throwing up an error when I add anything. Here I'll show the code of both classes without any of the interspersed html, for ease of reading - I'm not getting any errors which could be attributed to the html, so it shouldn't mislead:
<?php
class Base
{
public $content;
public $rhcolumn;
public $title = 'This Title';
public $keywords = 'seo chat up words';
public $description = 'seo chat up sentence.';
public $buttons = array('SECTION1' => 'section1_index.php',
'SECTION2' => 'section2_index.php',
'SECTION3' => 'section3_index.php',
);
public function __set($name, $value)
{
$this->$name = $value;
}
function display()
{
echo "<html>\n<head>\n";
$this -> displayTitle();
$this -> displayKeywords();
$this -> displayDescription();
$this -> displayStyles();
echo "</head>\n<body>\n";
$this -> displayHeader();
$this -> displayMenu($this->buttons);
echo $this->content;
$this -> displayFooter();
}
public function displayTitle()
{
echo "<title>$this->title</title>\n";
}
public function displayKeywords()
{
echo "<meta name=\"keywords\" content=\"".htmlentities($this->keywords)."\">\n";
}
public function displayDescription()
{
echo "<meta name=\"description\" content=\"".htmlentities($this->description)."\">";
}
public function displayStyles()
{
?>
<link rel="stylesheet" type="text/css" href=http://www.phpbuilder.com/board/archive/index.php/"styles.css">
<?php
}
public function displayHeader()
{
?>
// html for header
<?php
}
public function displayMenu($buttons)
{
foreach ($buttons as $name => $url)
{
$this -> displayButton($name, $url, !$this->IsURLcurrentPage($url));
}
?>
// a bit more html
<?php
}
public function IsURLcurrentPage($url)
{
if(strpos( $_SERVER['PHP_SELF'], $url )==false)
{
return false;
}
else
{
return true;
}
}
public function displayButton($name, $url, $active = true)
{
if ($active)
{
echo "<td align='center' valign='middle' bgcolor='#somecolor' width='75'>
<a href ='http://www.phpbuilder.com/board/archive/index.php/".htmlentities($url)."'><span class='bodytext1'>$name</span></a></td>";
}
else
{
echo "<td align='center' valign='middle' bgcolor='#anothercolor' width='75'>
<span class='bodytext1'>$name</span></td>";
}
}
public function displayFooter()
{
?>
// footer content as html
<?php
}
}
?>
and the Section1 Class:
<?php
require_once ('class.Base.php');
class Section1 extends Base
{
private $row2buttons = array('Page1' => 'section1_page1.php',
'Page2' => 'section1_page2.php',
'Page3' => 'section1_page3.php',
);
public function display()
{
echo "<html>\n<head>\n";
$this -> displayTitle();
$this -> displayKeywords();
$this -> displayDescription();
$this -> displayStyles();
$this -> displayHeader();
$this -> displayMenu($this->buttons);
$this -> displaySubmenu($this->row2buttons);
echo $this->content;
$this -> displayFooter();
}
}
?>
Obviously, I'm doing something wrong. Not being a trained programmer, I'm not sure what. The sort of errors I'm generating when I try to add definitions or otherwise alter the class.Section1.php script are unexpected T_PUBLIC, unexpected '}', parse errors. Equally obviously, I need to do something or it just ain't gonna work. can anyone tell me what I ought to be doing? I really don't mind reading it up, just a pointer in the right direction would be greatly appreciated.
Trying to build a site using PHP5's OO capabilities. The main navigation, in class.Base.php, should lead to the page indicated, and that works fine when I use an instanceof Base, say $index. Some of those pages are actually the first pages in thier own sections, so there's a sub-navigation bar which should show up for each of those, so I've built class.Section1.php. Problem is, when I create an instance, say $page1, the subnav is either reflecting the visual appearance of the main one when I use it as shown, or throwing up an error when I add anything. Here I'll show the code of both classes without any of the interspersed html, for ease of reading - I'm not getting any errors which could be attributed to the html, so it shouldn't mislead:
<?php
class Base
{
public $content;
public $rhcolumn;
public $title = 'This Title';
public $keywords = 'seo chat up words';
public $description = 'seo chat up sentence.';
public $buttons = array('SECTION1' => 'section1_index.php',
'SECTION2' => 'section2_index.php',
'SECTION3' => 'section3_index.php',
);
public function __set($name, $value)
{
$this->$name = $value;
}
function display()
{
echo "<html>\n<head>\n";
$this -> displayTitle();
$this -> displayKeywords();
$this -> displayDescription();
$this -> displayStyles();
echo "</head>\n<body>\n";
$this -> displayHeader();
$this -> displayMenu($this->buttons);
echo $this->content;
$this -> displayFooter();
}
public function displayTitle()
{
echo "<title>$this->title</title>\n";
}
public function displayKeywords()
{
echo "<meta name=\"keywords\" content=\"".htmlentities($this->keywords)."\">\n";
}
public function displayDescription()
{
echo "<meta name=\"description\" content=\"".htmlentities($this->description)."\">";
}
public function displayStyles()
{
?>
<link rel="stylesheet" type="text/css" href=http://www.phpbuilder.com/board/archive/index.php/"styles.css">
<?php
}
public function displayHeader()
{
?>
// html for header
<?php
}
public function displayMenu($buttons)
{
foreach ($buttons as $name => $url)
{
$this -> displayButton($name, $url, !$this->IsURLcurrentPage($url));
}
?>
// a bit more html
<?php
}
public function IsURLcurrentPage($url)
{
if(strpos( $_SERVER['PHP_SELF'], $url )==false)
{
return false;
}
else
{
return true;
}
}
public function displayButton($name, $url, $active = true)
{
if ($active)
{
echo "<td align='center' valign='middle' bgcolor='#somecolor' width='75'>
<a href ='http://www.phpbuilder.com/board/archive/index.php/".htmlentities($url)."'><span class='bodytext1'>$name</span></a></td>";
}
else
{
echo "<td align='center' valign='middle' bgcolor='#anothercolor' width='75'>
<span class='bodytext1'>$name</span></td>";
}
}
public function displayFooter()
{
?>
// footer content as html
<?php
}
}
?>
and the Section1 Class:
<?php
require_once ('class.Base.php');
class Section1 extends Base
{
private $row2buttons = array('Page1' => 'section1_page1.php',
'Page2' => 'section1_page2.php',
'Page3' => 'section1_page3.php',
);
public function display()
{
echo "<html>\n<head>\n";
$this -> displayTitle();
$this -> displayKeywords();
$this -> displayDescription();
$this -> displayStyles();
$this -> displayHeader();
$this -> displayMenu($this->buttons);
$this -> displaySubmenu($this->row2buttons);
echo $this->content;
$this -> displayFooter();
}
}
?>
Obviously, I'm doing something wrong. Not being a trained programmer, I'm not sure what. The sort of errors I'm generating when I try to add definitions or otherwise alter the class.Section1.php script are unexpected T_PUBLIC, unexpected '}', parse errors. Equally obviously, I need to do something or it just ain't gonna work. can anyone tell me what I ought to be doing? I really don't mind reading it up, just a pointer in the right direction would be greatly appreciated.