class - Change PHP Object Instance to a Parent -
i have class base has property called load object of class load. load class has function called view includes pages. need call,
this similar codeigniter's $this->load->view("test.php");
load class
class load { public function view($page){ //this function loads views display include($page); } public function model($class){ //loads model classes } public function library($class){ //loads libraries } }
base class
class base { function __construct(){ $this->load = new load(); } }
index page
$base = new base(); $base->load->view("test1.php");
this1.php
echo "testing1\n"; $this->load->view("test2.php");
test2.php
echo "testing2";
the output should be
testing1 testing2
what want think follow factory pattern. (at least, that's mean if want $view
variable contain instance of load
class)
make constructor protected, class can create new instances, in base class add static method, e.g. 'factory' returns instance of desired class.
then code like
$view=base::factory(); $view->view("test1.php");
Comments
Post a Comment