Echo tld基于当前会话id codeigniter

时间:2013-02-01 03:46:22

标签: php codeigniter session-variables

我有一个控制器

<?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_idcontroller之间正确传递了model,但事实并非如此?有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:2)

看起来Session库未加载。

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

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

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

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