簡體   English   中英

存儲會話並使用Codeigniter進行檢索

[英]To store session and retrieve using codeigniter

在下面的代碼點火器代碼中,我放置了模型和視圖。我的目的是將大學名稱存儲在會話中,並在其他表中檢索和使用。請幫助我做到這一點。 模型:

function validate()
    {
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
            $this->db->where('college_name', $this->input->post('college_name'));
        $query = $this->db->get('membership');

        return $query;

    }

視圖:

<?php 
    echo form_open('login/validate_credentials');
    echo form_input('username', 'Username');
    echo form_password('password', 'Password');
        echo form_input('college_name', 'college_name');
    echo form_submit('submit', 'Login');
    echo anchor('login/signup', 'Create Account');
    echo form_close();
    ?>

要在控制器構造函數中手動初始化Session類,請使用$this->load->library function:

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

要將數據添加到會話數組,需要將包含新數據的數組傳遞給此函數:

$this->session->set_userdata($array);

您可以在會話中設置數組,例如:

$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => 'johndoe@some-site.com',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);

有關更多詳細信息,請研究此鏈接

要在會話中設置數據:

$this->load->library('session');
$this->session->set_userdata("collegeName",$collegeName);

要獲取數據,請使用:

$data = $this->session->userdata("collegeName");

有關更多信息:( http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM