I am trying to get the php class Base
to load only once for a custom MVC framework. So that i can close the database connection in the destructor and be able to use it in inheritance but I can't seem to figure it out. I looked at a singleton design here but i cant figure out how to load the database. Is there a way to get this working or perhaps a better way to do this. Or am i going about this in a totally stupid way and should change it?
Base class
class Base {
protected $db;
//constructor
public function Base(){
echo some unique id to test it worked
$db = connection to database
}
//load modules as needed
public function load($m){
$this->$m = new $m;
}
}
module class
class module extends Base {
//some random function
public function listing(){
$this->db->query();
}
}
the index.php which initializes the Base class
$main = new Base;
$main->load( 'module' );
$main->module->listing();