Here is the basics of my framework:
class CPU {
public function load_class($class) {
include_once($class . ".php");
$this->$class = new $class;
}
public function load_controller($class) {
include_once($class . ".php");
$class = new $class;
$class->index();
}
public function run() {
// Load DB class
$this->load_class("DB");
// Load controller
$this->load_controller("About");
}
}
class About extends CPU {
public function index() {
$this->DB->connect();
}
}
When run()
is called to load the About
class, accessing $DB
gives the error below:
Fatal error: Call to a member function connect() on a non-object
I assume I need to use a singleton to create the class dynamically. CodeIgniter works in the same way but I can't work out what I have to do to amend my framework to make this work?