best practise loading in model $this vs get_instance() - 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: best practise loading in model $this vs get_instance() (/showthread.php?tid=22792) |
best practise loading in model $this vs get_instance() - El Forum - 09-20-2009 [eluser]jof[/eluser] Hi all I have a newbe question. In models I kan load for example a helper like this Code: $this->load->helper('email'); Or I can do it like this, and first grab the ci object by ref and then... Code: $this->ci =& get_instance(); the same seems to work for sessions. Code: $this->session->set_userdata('id', 100); Code: $this->ci =& get_instance(); What is the "correct way" to do this? In some code I have seen the 'get_instance' is used in models, but that seems not to be necessary? regards // Johannes best practise loading in model $this vs get_instance() - El Forum - 09-20-2009 [eluser]moodh[/eluser] Libraries, not models (as long as you extend the base model). That's because $this (CI's superglobal) doesn't exist in your libraries (your own libraries $this), that's why you load in the instance to access it. best practise loading in model $this vs get_instance() - El Forum - 09-20-2009 [eluser]jof[/eluser] ok, thanks! |