Welcome Guest, Not a member yet? Register   Sign In
Loading a model twice
#1

[eluser]4myGod[/eluser]
I have a model called member. Now in MY_Controller I load the model for the first time using $this->load->model('member','currentMember'). However on one of the pages I load the model again to get another users information, I use $this->load->model('member','memberModel') but this time I get an error: "Fatal error: Cannot redeclare class Member in ..."

What's wrong? How can I load the model twice?
#2

[eluser]toopay[/eluser]
The right question would be : why you need to load the model twice?
#3

[eluser]4myGod[/eluser]
I just explained. I need it one time for the user who is logged in and another time for the user who's profile he is viewing.
#4

[eluser]toopay[/eluser]
If, you loading a model at consctructor function, thats mean it already declared and available on any function on its scope! Theres no need to call/load it anymore.
#5

[eluser]4myGod[/eluser]
but I need two entirely separate instances of it though, one for the current member and one for the logged in member, how do I make 2 instances using codeigniter?
#6

[eluser]toopay[/eluser]
Code:
// If you have load a model in constructor like these
function __construct()
{
   parent::_construct();
   $this->load->model('some_model');
}

// Thats mean you can call it from any function in this class or sub-class scope!
function foo()
{
   $foo = $this->some_model->somedbfuction();
}

//...

// You can call it from here without need to load it again.
function bar()
{
   $bar = $this->some_model->somedbfuction();
}
#7

[eluser]4myGod[/eluser]
I found out the problem. The problem is that my model name was member and my controller name was member. So I renamed my model to member_model.

Thanks for the help.
#8

[eluser]InsiteFX[/eluser]
There still is no reason to load your model twice!

The model is already loaded so you can call any methods in it from any place!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB