Welcome Guest, Not a member yet? Register   Sign In
Model singleton

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?


You load a model like this:

You access it like this:

Not really an opportunity to load and access more than one instance. There may be a way around this but I haven't investigates.

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

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,




//in the race model..
function start(){

$this->pilot->setName("BB king");


$this->pilot->save(); //is now BB king right?

In the fw i have worked, the the pilot will have two instaces, in CI I think not,
its thats a Domain question?


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:

$myObj = new a_object();

What do you think about? thats right?

You can always alias a model using the second parameter
$this->load->model('pilot', 'pilot1');
$this->pilot1->setname("Pilot 1");

$this->load->model('pilot', 'pilot2');
$this->pilot2->setname("Pilot 2");

Theme © iAndrew 2016 - Forum software by © MyBB