0

I have a controller

<?php
class Onetimescan extends CI_Controller{
    public function index() {
        #LOAD MODEL
       $this->load->model('scanmodel');
            $this->scanmodel->loadurlbasedonsessid($this->session->userdata('session_id'));      
    }
}
?>

and a model:

<?php
class Scanmodel extends CI_Model{
    function __construct(){
        // Call the Model constructor
        parent::__construct();
    }

    function loadurlbasedonsessid($sid){
        $sid = $this->session->userdata('session_id');
        $this->db->select('tld');
        $this->db->where('session_id', $sid);
        $q = $this->db->get('ClientDomain');
        $r = $q->result_array();
        echo($r[0]['tld']);
    }   
}
?>

I'm getting the following error:

Call to a member function userdata() on a non-object

I thought I was properly passing the session_id in between the controller and model, but this isnt the case? Can someone please help?

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
CodeTalk
  • 3,571
  • 16
  • 57
  • 92

1 Answers1

2

It looks like the Session library isn't loaded.

To load it on demand (usually in the controller):

$this->load->library('session');

or add it to your application/config/autoload.php:

$autoload['libraries'] = array('session');
Brendan
  • 4,565
  • 1
  • 24
  • 39