CodeIgniter Forums

Full Version: Loading a Library with a different Name doesn't work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hello there,
my Problem is pretty simple:

I have written my own Form Class and I sometimes need more than one instance of it, with a different name.

This is working.

$this->load->library("MY_Form", "", "my_form2");
This is not.

It worked fine before Codeigniter 2.0 and now I get "Message: Undefined property: User::$my_form2".
Maybe I'm just too stupid to properly read the documentation, but I don't see a mistake on my side.

El Forum

Libraries are loaded as singletons, they're not supported to support multiple instances. If you want that, simply use "new Libraryname();". Loading it again won't work, it will just return the already loaded instance.

Are you using some kind of modular solution? Because your second code block should work without problems.

El Forum

The Lib loading is singleton? Well good to know. Smile

But like I said, that Code worked before 2.0.
And even if it's just returning another instance with a different name, this should still work, right?

I'm not using anything special that I'm aware of.
The Form Library is a normal Class that extends another Library Class.

Thanks for the tip with "new" anyway, because this works:
$this->my_form2 = new MY_Form();