non-object and userdata - 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: non-object and userdata (/showthread.php?tid=5492) |
non-object and userdata - El Forum - 01-23-2008 [eluser]Kemik[/eluser] Hello, I'm building a login page for my app and have encountered a problem. I'm not sure why but I get Fatal error: Call to a member function on a non-object in /home/sh/public_html/project/system/application/libraries/auth.php on line 60 when the page attempts to load. Here's the code (line below comment is 60) Code: function logged_in() { Edit: Forgot to mention, session library is autoloaded. non-object and userdata - El Forum - 01-23-2008 [eluser]Craig A Rodway[/eluser] Have you loaded the session library? non-object and userdata - El Forum - 01-23-2008 [eluser]Kemik[/eluser] Yeap. Autoloaded. The function is in an auth library which is also autoloaded. Here's the code taken from the user/login controller where the logged_in() function is called. Code: function login() non-object and userdata - El Forum - 01-23-2008 [eluser]wiredesignz[/eluser] Fatal error: Call to a member function on a non-object suggests $this->session is not visible to your library, you should use $CI = &get;_instance(); and then $CI->session->userdata('user_id') etc. non-object and userdata - El Forum - 01-23-2008 [eluser]Pascal Kriete[/eluser] EDIT: Forgot to refresh before reading... non-object and userdata - El Forum - 01-23-2008 [eluser]Kemik[/eluser] [quote author="wiredesignz" date="1201136854"]Fatal error: Call to a member function on a non-object suggests $this->session is not visible to your library, you should use $CI = &get;_instance(); and then $CI->session->userdata('user_id') etc.[/quote] I already do this at the start of the library: Code: class Auth { It's basically Erkana Auth with a few changes and additional functions. non-object and userdata - El Forum - 01-23-2008 [eluser]Pascal Kriete[/eluser] You got the instance, now you have to use it, too Code: $this->auth->logged_in() non-object and userdata - El Forum - 01-23-2008 [eluser]Kemik[/eluser] [quote author="inparo" date="1201137407"]You got the instance, now you have to use it, too Code: $this->auth->logged_in() Thanks for the suggestion. I tried the change you said but then it gave the same error but on the $this->CI->auth->logged_in() line. I tried changing Code: if ($this->session->userdata('user_id')) { But the original error didn't change. non-object and userdata - El Forum - 01-23-2008 [eluser]wiredesignz[/eluser] don't use $this->CI in your controller, only in your library. The Controller already is part of the CI Super-object non-object and userdata - El Forum - 01-23-2008 [eluser]Kemik[/eluser] Here's the current code. Controller - user.php Code: class User extends Controller Library - auth.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |