Asked  1 Year ago    Answers:  5   Viewed   13 times

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/ on line 13

Code in full located in the link below

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"]);



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"]);
Thursday, April 1, 2021

since get_all_contacts is already using the result() function in your model, you can't also use the result_array() function in your controller. result_array() would be a method of the $query object. The quick and dirty way to get this working(which might break other stuff if its also using the get_all_contacts method) would be to change your get all contacts function to the following:

function get_all_contacts() {
    $query = $this->db->query('SELECT * FROM person');
    return $query;

however, if you want to be smarter about it and not risk breaking other stuff, you can pass a param from the controller, and only return query if its set like so:


$allContacts = $this->people_model->get_all_contacts(true);


function get_all_contacts($special = false) {
    $query = $this->db->query('SELECT * FROM person');
        return $query;
    return $query->result();
Friday, May 28, 2021

Try this code it might help you :

Here dashboard is the name of controller

//this will route as localhost/appFolder/admin/index
  $route['admin'] = 'dashboard'; // for your index page

//this will route as localhost/appFolder/admin/method_name
 $route['admin/(:any)'] = 'dashboard/$1';

//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';

Link the route Like

// for your index page
<a href="<?php echo base_url('admin/index'); ?>"></a>

// for your other pages
<a href="<?php echo base_url('admin/method_name'); ?>"></a>

To link the other controller defined just like

 <a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>
Saturday, May 29, 2021

I'm so sorry! I dont know how come, but Bluehost info panel says PHP 5 is active. and i just believed that. when I make a php_info(); page just in case, i saw actually it is php 4 :/

I updated server for PHP5 and now everything is fine.

I'm sorry for messing. and thanks all you for great support!!!

Saturday, May 29, 2021

I think that you have to load the "database" library. The first way is to include the "database" in your application/config/autoload.php

$autoload['libraries'] = array('database', 'session');

or in your class constructor:

class User_model extends CI_Model { 

     public function __construct() 

You can get more information here:

Wednesday, August 4, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :