как я могу обновить данные пользователя, определяя пользователя, вошедшего в сеанс? сейчас я просто вставляю один идентификатор пользователя, чтобы проверить, работает ли мой код, но я не уверен, как использовать сеанс.войти в систему в codeigniter
мой контроллер
public function index(){
// check whether user login
if($this->session->userdata('is_logged_in')){
redirect('home');
}
else{
$this->login();
}
}
function update_user() {
$this->form_validation->set_rules('sirname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('name', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
if ($this->form_validation->run())
{
$data = array(
'surname' => $this->input->post('sirname'),
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
);
$this->Account_model->update_user(31,$data); //change the 31 id to session??
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Updated!</div>');
$this->load->library('form_validation');
// redirect('home');
}
else
{
$data['titile'] = 'Edit User';
$data['display'] = 'displayname';
$data['single_user'] = $this->Account_model->show_user(31);//change the 31 id to session??
$this->load->view('template/header.php', $data);
$this->load->view('update_view', $data);
}
}
моя модель
function show_user($data){
$this->db->where('pkid', $data);
$query = $this->db->get('users');
$query_result = $query->result();
return $query_result;
}
function show($data){
$this->db->select('*');
$this->db->from('users');
$this->db->where('pkid', $data);
$query = $this->db->get();
$result = $query->result();
return $result;
}
// Update Query For Selected Student
function update_user($id,$data){
$this->db->where('pkid', $id);
$this->db->update('users', $data);
}
Прочтите этот учебник http://w3code.in/2015/10/session-handling-in-codeigniter/ – Ricky