我有一个控制器
<?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
我以为我在session_id
和controller
之间正确传递了model
,但事实并非如此?有人可以帮忙吗?
由于
答案 0 :(得分:2)
看起来Session库未加载。
按需加载(通常在控制器中):
$this->load->library('session');
或将其添加到您的application/config/autoload.php
:
$autoload['libraries'] = array('session');