0

我知道如果您加载库,codeigniter 会为您设置会话。但是,我想有自己的一套规则。我想我可以通过添加用户数据并检查它是否存在于每个页面加载来做到这一点。但是,它不起作用...

这是我的欢迎控制器...

class Welcome extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        //$this->output->enable_profiler(TRUE);

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->helper('url');
    }

    function index($cliqid='', $cliq=false)
    {
        $default_cliq = 5; //this equals whatever the user sets
        $this->page_m->load_session($default_cliq); //check to see if session is new; if so, perform list of actions
        //$this->session->sess_destroy();
        print_r($this->session->all_userdata());
    }
}

它指向 page_m,它由加载会话方法组成,我想在其中应用一些会话变量以在访问者停留在页面上的整个过程中使用:

这是一个简短的摘录:

class Page_m extends CI_Model
{
function __construct()
{
    parent::__construct();
    $this->load->model('cliq_info_m');
}

function load_session($default_cliq)
{
    //check if session is new
    if ($this->session->userdata('exists') == true) {
        //the list of things to do
        $this->record_session();   //check if ip exists in DB, if not, record     
        $this->cliq_info_m->change_active($default_cliq);

        //make session old
        $data['exissts'] = true;
        $this->session->set_userdata($data); 
    } else {
        return false;
    }
}

会发生什么……它是否每次都运行,而不管“存在”变量如何。

有谁知道为什么?以及可能的解决方案?

4

1 回答 1

1

It appears that the reason for the error was the fact that I had heading errors (echoing the script alert). Once i removed all that, it started working...

于 2013-09-16T17:35:31.470 回答