0

我有一个控制器

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

和一个模型:

<?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']);
    }   
}
?>

我收到以下错误:

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

我以为我在 and 之间正确传递了,session_id但事实并非如此?有人可以帮忙吗?controllermodel

谢谢

4

1 回答 1

2

看起来会话库没有加载。

按需加载(通常在控制器中):

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

或将其添加到您的application/config/autoload.php

$autoload['libraries'] = array('session');
于 2013-02-01T03:53:42.483 回答