Model singleton |
[eluser]ClaudioX[/eluser]
Hi all, I'm reading this document conceptric.co.uk/, and in some point of the text he said: Quote:CodeIgniter Models implement the Singleton design pattern, now i have a doubt, when i'm load one model, the instance (and properties) are sharing across the application? Thanks
[eluser]Jondolar[/eluser]
You load a model like this: $this->load->model('Model_name'); You access it like this: $this->Model_name->function(); Not really an opportunity to load and access more than one instance. There may be a way around this but I haven't investigates.
[eluser]Dam1an[/eluser]
Without reading the article, are you concerned that the variables in my instance of a model will overwrite yours? Cause if thats your concern I'm pretty sure thats not the case Each HTTP reqiuest gets its own instance of CI, so that instance of a model is just yours
[eluser]ClaudioX[/eluser]
Thanks for the reply, jondolar, i understand that to. Damian, I was concerned about the issue you raised, and you have completely solved, ty man! but the original matter is: i think in aplication when i use more than one model, and more than one time, if i have, Code: $this->load->model("pilot"); In the fw i have worked, the the pilot will have two instaces, in CI I think not, its thats a Domain question? UPDATE: Studing a way, i found ellislab.com/forums/viewthread/49625/#247644 now i think in the submodels, use this form to do a new load: Code: $this->load->mode('a_object'); What do you think about? thats right?
[eluser]Dam1an[/eluser]
You can always alias a model using the second parameter Code: $this->load->model('pilot', 'pilot1'); |
Welcome Guest, Not a member yet? Register Sign In |