CodeIgniter Forums
Multiple models in 1 variable - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Multiple models in 1 variable (/showthread.php?tid=54074)



Multiple models in 1 variable - El Forum - 08-21-2012

[eluser]Unknown[/eluser]
I got this problem
i need to load a model dynamically

like this
Code:
$this->load->model($fila_destino->nombre,'tabla_temp');
$data2=$this->tabla_temp->loggin($data->idusuario);
being $fila_destino->nombre, the name of the model to charge, but when i call the function loggin of tabla temp (the second line of the code), it's always charge the first model (the bug occurs when the $fila_destino->nombre it's different than the first time it's called.
An example. i need to load in the first time the model "model1" and load in 'tabla_temp'
and the second time to "model2" and load to in "tabla_temp" but, the second time the model "model2" doesn't load on 'tabla_temp' besides 'tabla_temp' it's an instance of "model1".






Multiple models in 1 variable - El Forum - 08-21-2012

[eluser]TWP Marketing[/eluser]
[quote author="Ernesto2456" date="1345570527"]I got this problem
i need to load a model dynamically

like this
Code:
$this->load->model($fila_destino->nombre,'tabla_temp');
$data2=$this->tabla_temp->loggin($data->idusuario);
being $fila_destino->nombre, the name of the model to charge, but when i call the function loggin of tabla temp (the second line of the code), it's always charge the first model (the bug occurs when the $fila_destino->nombre it's different than the first time it's called.
An example. i need to load in the first time the model "model1" and load in 'tabla_temp'
and the second time to "model2" and load to in "tabla_temp" but, the second time the model "model2" doesn't load on 'tabla_temp' besides 'tabla_temp' it's an instance of "model1".
[/quote]
Does your variable:
Code:
$fila_destino->nombre
contain a valid model name?
Is it capitalized as in 'Model1' or 'Model2' which I think are the class names of your model classes.


Multiple models in 1 variable - El Forum - 08-21-2012

[eluser]Unknown[/eluser]
Yes, the variable
Code:
$fila_destino->nombre
always give me a valid model name, indeed when i used with the other models, works , the problem is just when i called the funcion 2 times and the second time the variable.
Code:
$fila_destino->nombre
give me. another string (a valid model name).
i tried with
Code:
$this->tabla_temp=null;
and
Code:
unset($this->tabla_temp);
but it didn't work. throw me an error