xtiano77
02-02-2009, 03:25 AM
Hello. I am new to PHP and I must say that I like it. I am trying to make a php page that echoe its code from a PHP class. However, I am having trouble getting the page content to show. I am including the code for both files below. Thanks in advance for your help.
Main page, "index.php":
<?php
require('pageclass.php');
$newpage = new pageclass();
$newpage -> $contents = "<p>Test<br />Test</p>";
$newpage -> displaypage();
?>
****************
PHP class file:
<?php
class pageclass{
public $contents;
public function __set($a,$b){
$this -> $a = $b;
}
public function opening1(){
echo "<!DOCTYPE html PUBLIC \"-//W3C/DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml/DTD/xhtml11-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
echo "<head>\n";
echo "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n";
}
public function css(){
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/default.css\" />\n";
}
public function javascript(){
echo "<script type=\"text/javascript\" src=\"../scripts/default.js\"></script>\n";
echo "<script type=\"text/javascript\">\n";
echo "\tif(top != self){\n";
echo "\t\ttop.href = \"http://www.xtianos.com/test/index.php\"\n";
echo "\t}\n";
echo "</script>\n";
}
public function opening2(){
echo "<title>Indes PHP Page</title>\n";
echo "</head>\n";
echo "<body>\n";
}
public function navigationbar(){
echo "\t<div class=\"navbuttons center\">\n";
echo "\t\t<ol>\n";
echo "\t\t\t<li><a href=\"pages/familyphotos.php\">Family Photos</a></li>\n";
echo "\t\t\t<li><a href=\"#\">Recipes</a></li>\n";
echo "\t\t\t<li><a href=\"#\">New Home Photos</a></li>\n";
echo "\t\t\t<li><a href=\"#\">Supplements</a></li>\n";
echo "\t\t</ol>\n";
echo "\t</div>\n";
}
public function pagecontents(){
echo $contents;
}
public function closing(){
echo "</body>\n";
echo "</html>\n";
}
public function displaypage(){
$this -> opening1();
$this -> css();
$this -> javascript();
$this -> opening2();
$this -> navigationbar();
echo $this -> contents;
$this -> closing();
}
}
?>
Main page, "index.php":
<?php
require('pageclass.php');
$newpage = new pageclass();
$newpage -> $contents = "<p>Test<br />Test</p>";
$newpage -> displaypage();
?>
****************
PHP class file:
<?php
class pageclass{
public $contents;
public function __set($a,$b){
$this -> $a = $b;
}
public function opening1(){
echo "<!DOCTYPE html PUBLIC \"-//W3C/DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml/DTD/xhtml11-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
echo "<head>\n";
echo "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n";
}
public function css(){
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/default.css\" />\n";
}
public function javascript(){
echo "<script type=\"text/javascript\" src=\"../scripts/default.js\"></script>\n";
echo "<script type=\"text/javascript\">\n";
echo "\tif(top != self){\n";
echo "\t\ttop.href = \"http://www.xtianos.com/test/index.php\"\n";
echo "\t}\n";
echo "</script>\n";
}
public function opening2(){
echo "<title>Indes PHP Page</title>\n";
echo "</head>\n";
echo "<body>\n";
}
public function navigationbar(){
echo "\t<div class=\"navbuttons center\">\n";
echo "\t\t<ol>\n";
echo "\t\t\t<li><a href=\"pages/familyphotos.php\">Family Photos</a></li>\n";
echo "\t\t\t<li><a href=\"#\">Recipes</a></li>\n";
echo "\t\t\t<li><a href=\"#\">New Home Photos</a></li>\n";
echo "\t\t\t<li><a href=\"#\">Supplements</a></li>\n";
echo "\t\t</ol>\n";
echo "\t</div>\n";
}
public function pagecontents(){
echo $contents;
}
public function closing(){
echo "</body>\n";
echo "</html>\n";
}
public function displaypage(){
$this -> opening1();
$this -> css();
$this -> javascript();
$this -> opening2();
$this -> navigationbar();
echo $this -> contents;
$this -> closing();
}
}
?>