Am I missing something? - 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: Am I missing something? (/showthread.php?tid=52031) |
Am I missing something? - El Forum - 05-27-2012 [eluser]Unknown[/eluser] I'm working on creating my first library (CI 2.1.0) and I'm having a hard time believing that every time I create a new functions that needs a CI resource I have to set it up as a varibale: Code: $CI =& get_instance(); I've tried creating it in a __construct() statement and that doesn't seem to work. I have a feeling I'm missing something so easy... Am I missing something? - El Forum - 05-27-2012 [eluser]CroNiX[/eluser] It works fine in a construct. You probably just aren't accessing it correctly within the class. I'm guessing you declared it locally in your construct but didn't assign it to a property you can access from everywhere within the class. Code: class your_library { Am I missing something? - El Forum - 05-27-2012 [eluser]Unknown[/eluser] the only difference in your code, which is working, is Code: $this-> Am I missing something? - El Forum - 05-27-2012 [eluser]CroNiX[/eluser] Because if you don't then it's only locally available to the method it was declared in (in this case the constructor) instead of globally throughout the class, just like regular procedural php. |