2

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

1 回答 1

1

你可以试试这个,希望对你有帮助

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

$token['answer']从会话中获取数组数据:

$token_from_session = $this->session->userdata('token'); //return $token['answer'] array
于 2013-09-25T20:02:13.467 回答