简体   繁体   中英

Saving Array to a Session and Retrieve it, CodeIgniter

So $token here is an array of data from the database, I would like to retrieve it in the view . I know that the data is already there by using print_r($this->session->all_userdata()); but I would like to retrieve the values from the $token array and use it.

Controller:

$token['answer']=$this->Qmodel->get_answers();
$data= array(
    'username' => $this->input->post('username'),
    'is_logged'=> 1,
    $token
);

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

You can try with this one,I hope it will help you

 $token['answer']=$this->Qmodel->get_answers();
    $data= array(
                'username' => $this->input->post('username'),
                'is_logged'=> 1,
                'token' => $token['answer'] // assign $token['answer'] array into token
                );

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

get $token['answer'] array data from session:

$token_from_session = $this->session->userdata('token'); //return $token['answer'] array

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