I created this class and saved it as classes.php. I then create a file called index.php which includes a file that sets the variables. And I have made a file which sets the variables to be displayed. The classes.php file is included through the environment file which is included on the index page at the top. Then when i run the index.php it doesnt work.I am given the error Fatal error: Call to a member function DisplayTitle() on a non-object in Z:\oop\classes.php on line 39
Contents of classes.php
<?
/* - - - - - - - - - - - - - - - - - - - - - - -
@files classes.php
@purpose builds the page dynamically
@package THNN Website Software
@version 2.0
@copyright (C)2005 Totally Hogwarts News Network. All rights reserved.
- - - - - - - - - - - - - - - - - - - - - - - */
class page
{
// class Page's attributes
var $content;
var $title;
//class Pages' operations
function SetContent($pagecontent)
{
$page->content = $pagecontent;
}
function SetTitle($pagetitle)
{
$page->title = $pagetitle;
}
function DisplayTitle()
{
echo "<title>Totally Hogwarts News Network $page->title </title>";
}
function DisplayStyles()
{
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"layout/style.css\">";
}
function DisplayHeaders()
{
$page -> DisplayTitle();
$page -> DisplayStyles();
}
function DisplayPage()
{
echo $page->content;
}
function IsURLCurrentPage($url)
{
if(strpos( $GLOBALS['SCRIPT_NAME'], $url) == false)
{
return false;
}
else
{
return true;
}
}
}
?>
Contents of index.php
<?php
require ("Z:\environment.php");
$homepage = new page();
if (isset($_GET['m'])==false)
{
$include = 'news.php';
require($include);
}
else
{
$module = $_GET['m'];
$include = "modules/".$module.".php";
if (is_file($include)==true)
{
require($include);
}
else
{
$homepage -> SetContent('Page not found');
}
}
?>
<html>
<head>
<?php
$homepage -> DisplayHeaders();
?>
</head>
<body>
<?php
$homepage -> DisplayPage();
?>
</body>
</html>
Contents of news.php
<?php
$homepage -> SetTitle('Banana');
$homepage -> SetContent('Hey');
?>
Any help would be appreciated.
Thanks
Contents of classes.php
<?
/* - - - - - - - - - - - - - - - - - - - - - - -
@files classes.php
@purpose builds the page dynamically
@package THNN Website Software
@version 2.0
@copyright (C)2005 Totally Hogwarts News Network. All rights reserved.
- - - - - - - - - - - - - - - - - - - - - - - */
class page
{
// class Page's attributes
var $content;
var $title;
//class Pages' operations
function SetContent($pagecontent)
{
$page->content = $pagecontent;
}
function SetTitle($pagetitle)
{
$page->title = $pagetitle;
}
function DisplayTitle()
{
echo "<title>Totally Hogwarts News Network $page->title </title>";
}
function DisplayStyles()
{
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"layout/style.css\">";
}
function DisplayHeaders()
{
$page -> DisplayTitle();
$page -> DisplayStyles();
}
function DisplayPage()
{
echo $page->content;
}
function IsURLCurrentPage($url)
{
if(strpos( $GLOBALS['SCRIPT_NAME'], $url) == false)
{
return false;
}
else
{
return true;
}
}
}
?>
Contents of index.php
<?php
require ("Z:\environment.php");
$homepage = new page();
if (isset($_GET['m'])==false)
{
$include = 'news.php';
require($include);
}
else
{
$module = $_GET['m'];
$include = "modules/".$module.".php";
if (is_file($include)==true)
{
require($include);
}
else
{
$homepage -> SetContent('Page not found');
}
}
?>
<html>
<head>
<?php
$homepage -> DisplayHeaders();
?>
</head>
<body>
<?php
$homepage -> DisplayPage();
?>
</body>
</html>
Contents of news.php
<?php
$homepage -> SetTitle('Banana');
$homepage -> SetContent('Hey');
?>
Any help would be appreciated.
Thanks
