我想在會話中設置用戶數據。我可以在會話數據中設置電子郵件,因爲我從登錄表單中獲取它。 但我不知道如何從數據庫中獲取所有細節並設置爲會話。這裏是我的代碼codeigniter會話用戶數據設置
控制器:
public function login_validation() {
// get form input
$email = $this->input->post("email");
$password = $this->input->post("password");
// form validation
$this->load->library('form_validation');
$this->form_validation->set_rules("email", "Email-ID", "trim|required");
$this->form_validation->set_rules("password", "Password", "trim|required");
if ($this->form_validation->run() == FALSE)
{
// validation fail
$this->load->view('admin/login');
}
else
{
// check for user credentials
$this->load->model('site_model');
$uresult = $this->site_model->get_user($email, $password);
$data["results"]=$this->site_model->getdata_user($email);
foreach ($data as $row) {
$fname = $row['fname'];
}
if (count($uresult) > 0)
{
$data = array(
'email' => $email,
'fname' => $fname,
'lname' => $lname,
'pre'=>$pre,
'is_logged_in' => 1
);
// set session
$this->session->sess_expiration = '0';// will not expire
$this->session->set_userdata($data);
redirect("admin/index");
}
else
{
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Wrong Email-ID or Password!</div>');
$this->load->view('admin/login');
}
}
}
型號:
function getdata_user($email)
{
$query= $this->db->get_where("users", array("email"=>$email));
return $query->result();
}
有一些的Fileds在用戶表:FNAME,LNAME,我要設置爲會話。
謝謝你提前。
你能請幫我用我的代碼。請:)我是codeigniter的新手。 –
我得到了模型部分。如何將這些數據傳遞給控制器,然後將其設置爲會話。請看我的代碼。謝謝 –
您從查詢變量讀取? – Webbanditten