Welcome Guest, Not a member yet? Register   Sign In
Loading a Library with a different Name doesn't work
#1

[eluser]Unknown[/eluser]
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.

Code:
$this->load->library("MY_Form");
$this->my_form->setTargetUrl($targetUrl);
This is working.

Code:
$this->load->library("MY_Form", "", "my_form2");
$this->my_form2->setTargetUrl($targetUrl);
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.
#2

[eluser]WanWizard[/eluser]
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.
#3

[eluser]Unknown[/eluser]
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:
Code:
$this->my_form2 = new MY_Form();




Theme © iAndrew 2016 - Forum software by © MyBB