CodeIgniter Forums
Loading two models in one view, causes problems? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Loading two models in one view, causes problems? (/showthread.php?tid=7231)



Loading two models in one view, causes problems? - El Forum - 03-31-2008

[eluser]geshan[/eluser]
Hello all code igniter users,
I had to load two models in the same view how can I do it? it shows no erros when I load the second model in the view but when I call a function of the second model it gives me error says the 2nd model name is not identified. How can I load two models in one view?


Loading two models in one view, causes problems? - El Forum - 03-31-2008

[eluser]xwero[/eluser]
It should be no problem if you load the models in your controller.


Loading two models in one view, causes problems? - El Forum - 03-31-2008

[eluser]Tom Glover[/eluser]
Load your models in the controller and then out put the function a var that is handled by the view.

An example:
Controller:
Code:
function index()
    {
        $this->load->model('model_1');
        $this->load->model('model_2');
        
        $data['out1'] = $this->model_1->function1($vars);
        $data['out2'] = $this->model_2->function2($vars);
        
        $this->load->view('view_1',$data)
        // just call the var out1 or out 2 where needed in the view file.
    }

Just echo the the out1 or out2 where needed in the view file.

Hope this helps.