Problem with constructor in library - 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: Problem with constructor in library (/showthread.php?tid=13254) |
Problem with constructor in library - El Forum - 11-16-2008 [eluser]CIfan1000[/eluser] Hi guys! I have the following simple library, it works fine without the constructor but when I put in the constructor I get: Quote:Fatal error: Cannot access parent:: when current class scope has no parent in C:\Backup\Apache2.2\htdocs\CodeIgniter\system\application\libraries\Myauth.php on line 15 Any help would be very much appreciated! Code: <?php Thanks! Problem with constructor in library - El Forum - 11-16-2008 [eluser]Pascal Kriete[/eluser] Libraries do not extend the controller, so you don't need that line. Problem with constructor in library - El Forum - 11-16-2008 [eluser]CIfan1000[/eluser] Hi, I am sorry but I don't quite understand - I am fairly new to constructors. The manual doesn't seem to explain constructors within a custom library and I have searched the forum and not found anything that helps me. I currently have the lines: Code: $CI =& get_instance(); In my function check_if_logged_in() and this works fine. However, I would like to have multiple functions in this library and so I would like to load the session library in a constructor so it is available for all functions in the library. I took the Code: parent::Controller(); Code: // Create constructor to load CI libaries and helpers: This also gives me errors - sorry that I don't understand your instructions. Am I mistaken thinking that I can use a constructor in a library? Am I mistaken thinking I can load the session library in the constructor and have it available for all functions in the library? Or do I need to load the session library in each function? Thanks! Problem with constructor in library - El Forum - 11-16-2008 [eluser]dmorin[/eluser] You only need to load the session library once, whether you do it in the controller or library doesn't matter. Instead of doing this in your constructor: Code: $CI =& get_instance(); do this Code: $this->CI =& get_instance(); That way, you can access anything like you normally would using $this->CI->session instead of $this->session. |