CodeIgniter Forums
helper problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: helper problem (/showthread.php?tid=34965)



helper problem - El Forum - 10-15-2010

[eluser]macron[/eluser]
I've taken over a ci project made in some old version (1.6ish) and upgraded it to 1.7.2, but I have a repeating problem on a few helpers and the usage of db.
in my controller I can do a regular $this->db->xxx. No problem. So I move this to a helper using $CI = &get;_instance(); But here I get an error on $CI->db->xxx stating db is an undefined property. Strange, I thought that &get;_instance gave a reference to the working ci object and hence one with db since I could do the db-> before a call to a function in the helper.

Any thoughts ?


helper problem - El Forum - 10-15-2010

[eluser]WanWizard[/eluser]
I assume you mean
Code:
$CI =& get_instance();
?


helper problem - El Forum - 10-15-2010

[eluser]macron[/eluser]
Yes. Typo. My bad. Of course $ci = & get_instance();


helper problem - El Forum - 10-15-2010

[eluser]WanWizard[/eluser]
If you do a
Code:
$CI =& get_instance();
var_dump($CI);
What do you get?


helper problem - El Forum - 10-17-2010

[eluser]macron[/eluser]
function get_active_languages()
{
$CI = &get;_instance();
var_dump($CI);

=>

object(user)#23 (10) {...}

Anything specific I have to look for in the Obj. Its quite large as you know?


helper problem - El Forum - 10-17-2010

[eluser]tonanbarbarian[/eluser]
the only way that $CI->db is undefined is if the database has not been loaded, or if some processes has unset the db property.
is your database autoloaded? (i would suggest probably not)
if the helper being called in an instance in which the database has not been previously loaded?


helper problem - El Forum - 10-17-2010

[eluser]Unknown[/eluser]
I asked so many times to so many people to give a clear answer of my question,but no one gave the right answer.Can any one give me the right answer of my question?