indigo diingo Posted September 15, 2009 Share Posted September 15, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.