问题
I am getting a fatal error in a CI app that I just moved from a php4 shared host to a php5 shared host.
Fatal error: Call to a member function set_userdata() on a non-object in /home/chuck_ravenna/bob.ravennainteractive.com/system/application/helpers/authenticate_helper.php on line 13
Code in full located in the link below
https://gist.github.com/1474173
I am trying to figure out if the php version could be the issue. The site runs fine on the old server, and the new server doesn't have php4 as an option.
The specific code line thats breaking is:
$this->session->set_userdata("admin", $user[0]["admin"]);
回答1:
You can't use $this
inside a helper as a helper file is just a collection of functions (no class there). To use the functionality provided by $this
of controller, you'll have to do:
$ci = & get_instance();
$ci->session->set_userdata("admin", $user[0]["admin"]);
回答2:
$CI =& get_instance();
$CI->load->library('session');
回答3:
Are you loading the session librairy in the constructor and after the parent::__construct() instruction?
回答4:
You are using the default configuration of Codeigniter. The problem is: NO DATABASE CONFIGURATION DONE! You must enter here: \YOUR_APPLICATION_NAME\application\config\database.php
and you must open this file with a text editor.
Set the following variables and you are done:
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "127.0.0.1";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "NameOfYourDatabase";
来源:https://stackoverflow.com/questions/8497052/codeigniter-call-to-a-member-function-set-userdata-on-a-non-object