Call to a member function on a non-object
Posted: Fri Jul 24, 2009 10:57 am
I'm a bit of a newbie to object oriented PHP. There are three classes: db.class.php (for database functions), page.class.php (for templating and page display), and session.class.php (for logging in and out).
index.php includes the required template stored in the templates folder and starts the required objects.
But i keep getting this error whenever I call to a function in page.class.php
templates/dashboard.php
page.class.php
index.php includes the required template stored in the templates folder and starts the required objects.
But i keep getting this error whenever I call to a function in page.class.php
index.php (minus the html)Fatal error: Call to a member function get_website_stats() on a non-object in C:\xampp\htdocs\kingsdale\admin\templates\dashboard.php on line 9
Code: Select all
<?php
// required files
require_once("classes/db.class.php");
require_once("classes/page.class.php");
require_once("classes/session.class.php");
// new db object
$db = new db;
// check database connection
if (!$db->connect())
$db->print_last_error(false);
// new page and templating objects
$page = new page;
// new session object
$session = new session;
// html head below
?>
<?php
// check if user is logged in
if(!$session->loggedIn && $template['protected']) {
include("templates/login.php");
} else {
?>
// html body
<?
$page->load_template();
}
?>Code: Select all
<div class="med">
<div class="head">
<div class="text">Website Statistics</div>
<div class="clear"></div>
</div>
<div class="boxcontent">
<?=$page->get_website_stats();?>
</div>
<div class="wht"></div>
</div>Code: Select all
<?php
class page {
function load_template() {
if($template['tpl']) {
// include page template
$tpl_path = "templates/".$template['tpl'].".php";
// check that template exists
if(file_exists($tpl_path)) {
include($tpl_path);
} else {
echo "Cannot find template, ".$tpl_path;
}
} else {
// load dashboard as default
include("templates/dashboard.php");
}
}
function get_website_stats() {
$r = $this->db->select("SELECT * FROM modules WHERE active = '1' ORDER BY rank");
while ($row=$this->db->get_row($r, 'MYSQL_ASSOC')) {
include('modules/'.$row['path'].'/stats.php');
}
}
}
?>