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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.