How can I instantiate multiple instances of the same object in Codeigniter? How can I instantiate multiple instances of the same object in Codeigniter? codeigniter codeigniter

How can I instantiate multiple instances of the same object in Codeigniter?


You don't have to use the load() functions. You can just use require_once and new User(), like you normally would.

Using the load() should only be for things you want in the global CI namespace. As you can see, it gets polluted really quickly if you try to use it for everything.


You can still instantiate objects in codeigniter the same way as you do it normally.

$user1 = new Users(); // Instantiate$user2 = new Users();$user1->property;     // Using it$user2->method()unset($user1);        // Unset it when done for good practice.


Yes, what JustAnil and minboost said are correct, however, standard practice for how the majority of CI developers write code is with the following syntax

$this->mymodel->mymethod(); 

Are you finding a particular problem or issue when you are trying to write like this? Or is it just different from the style you are used to writing in? Please elaborate on a use case where "it's not as dynamic as simply assigning an instance to a variable" :)