Dynamically load class for global access (like codeigniter does)

Cokaric

New Member
Here is the basics of my framework:\[code\]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(); }}\[/code\]When \[code\]run()\[/code\] is called to load the \[code\]About\[/code\] class, accessing \[code\]$DB\[/code\] gives the error below:Fatal error: Call to a member function connect() on a non-objectI 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?
 
Back
Top