CodeIgniter Forums
Instantiate model from helper - 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: Instantiate model from helper (/showthread.php?tid=52430)



Instantiate model from helper - El Forum - 06-10-2012

[eluser]nebulom[/eluser]
Is there a way I can instantiate my model from helper? I would like to it like this:

Code:
# user_helper.php
function user_form_session($session) {
$user = new User_model();
$user->email = $session['email'];
$user->password = $session['password'];
return $user;
}

Thanks.


Instantiate model from helper - El Forum - 06-11-2012

[eluser]nebulom[/eluser]
Solved. Load the model from controller who is using the helper.


Instantiate model from helper - El Forum - 06-11-2012

[eluser]johnpeace[/eluser]
Or do it like this:

[code] $CI =& get_instance();
$CI->load->model('your_model');
$CI->your_model->user_form_session($data);
[code]