Jump to content

My problem with the loader class from my own PHP framework.


indigo diingo

Recommended Posts

Hello everybody!

 

 

I am building a little PHP framework to build my application on. I almost have everything working great but i have a problem with the loader class and i feel i am never going to solve it on my own.

 

So i have base.php, my base class which instantiates the Loader class ('load'). So every time i need to load the library  i just call $this->load->lib('myobject') from within the base class.

Now the problem is that the loader class instantiate the library objects withinn the Loader class. So every time i want to access them through the base class or any childclass of the base, i need to call: $this->load->myobject->dosomething().

 

Instead of that i wanna be able to just call it like $this->myobject->dosomething(). Why do I want this syntax? Because it's shorter, more clear, and makes more sense (you don't load the object again, it's already loaded).

 

How can i accomplish this?

 

class Loader {

public function __construct() {}


public function lib($objects) {

	foreach($objects as $var) {
		// capitalize the first letter
		$object = ucfirst($var);

		// load the class
		require_once __LIB__PATH . $var . '/' . $var . '.php';

		// instantiate the class
		$this->$var = new $object();
	}
}
}

 

Thanks a lot

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.