Juan Tamad
Juan Tamad

Reputation: 65

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);

Upvotes: 2

Views: 9585

Answers (1)

Suvash sarker
Suvash sarker

Reputation: 3170

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

Upvotes: 1

Related Questions