简体   繁体   中英

i need some help about using sessions in code igniter

I am using codeigniter. I used session variable to store a id in a function and get the stored value in another function. I have a controller file which is given below:

public function select_service($id)
    {
    $this->load->library('session');
         $this->session->unset_userdata('employee');
         $this->session->set_userdata('employee', ['total'=>$id]);
     // $id = $this->uri->segment(4);
    $data['service'] =   $this->add_service_model->get_services();  
            $data['main_content'] = 'admin/service_limitation/service_view';
        $this->load->view('includes/template', $data);  

    }

In the above code I get the id from a form and store in the session variable

public function services()
    {
    //here i need to get the session variable employee['total'] 
    $id = $this->uri->segment(5);
    $data_to_store=array('employee_id'=>$id,'service_id'=>$this->input->post("services"));
    $this->add_service_model->save($data_to_store);
    $data['addservice'] =    $this->add_service_model->get_addservices();   
            $data['main_content'] = 'admin/service_limitation/newview';
        $this->load->view('includes/template', $data);  

    }

In this function service I need to retrieve the stored value. both functions are in same controller. can some one help me with the code?

Manuall

  1. Auto load the session library. This way the session is always loaded.

  2. when setting the id do: $this->session->set_userdata('employee', $id);

  3. when you want to get that id user $id = $this->session->userdata('employee');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM