I am having trouble on accessing to an instance of a singleton class in PHP MVC. Basically the MVC looks like
First of all I have included and instantiated objects in the init.php
as
// include objects
include('app/Database.php');
include('app/models/m_template.php');
include('app/models/m_categories.php');
// create objects
$tdatabase = new Database();
$Template = new Template();
$Categories = new Categories();
and in m_categories.php
I tried to use the $tdatabase
object as:
<?php
class Categories {
private $db_table = 'category';
function __construct() { }
public function get_categories() {
$data = array();
$res = $tdatabase->query("SELECT * FROM " . $this->db_table . " ORDER BY name");
foreach ($res as $dataRow):
$data[] = array('id' => $dataRow['id'],
'name' => $dataRow['name'],
'img' => $dataRow['img'],
'alt' => $dataRow['alt'],
);
endforeach;
return $data;
}
}
and finally in index.php
I have:
<?php
include('app/init.php');
echo '<pre>';
print_r($Categories->get_categories());
echo '</pre>';
but I am getting following errors:
can you please let me know why this is happening and how I can fix this?
Update 1:
Update 2