如何使用会话在codeigniter中将数据从一个函数传递到另一个函数?

时间:2014-08-30 15:27:29

标签: php codeigniter session

当我将数据设置为会话并打印会话数据时,我试图将一些数据从一个函数传递到另一个函数,我得到了正确的数据,但是当试图在另一个函数中使用数据时,我得到了单词"资产"我不知道这个词的来源。会话库是自动加载的。请帮忙。 这些是我的代码:

第一个功能:

      $client_id = $this->uri->segment(3);
      $sess_array = array(
                     'cl_id' => $client_d,
                     'selected_client'=>TRUE,
                   );
     $this->session->set_userdata('selected_client',$sess_array);

第二功能:

    $client_sess = $this->session->userdata('selected_client');
     $client_id= $client_sess['cl_id'];

2 个答案:

答案 0 :(得分:0)

尝试这个我认为这会给你一些想法。

function one(){
  $client_id = $this->uri->segment(3);
      $sess_array = array(
                     'cl_id' => $client_d,
                     'selected_client'=>TRUE,
                   );
    $this->two($sess_array);

}
function two($id){
   $client_id= $id;
}

答案 1 :(得分:0)

以下是模型的样子:

function getResponse($gettingresponse)

{

$enrollresponse=$gettingresponse['sendresponse'];

return $enrollresponse;

}

控制器如下:

public function Register()

{

   $this->load->view('firstview');

   $this->load->view('secondview');

   if($_POST) {

       $gettingresponse=array(

           'sendresponse'=>$_POST['source'],

           'receiverresponse'=>$_POST['destination']

       );

       $registration_confirm=$this->systemModel->responselogin($gettingresponse);

       $resposeflag=$this->systemModel->getEmail($gettingresponse);

       $data['resposeflag']=$gettingresponsevalue;

       if($registration_confirm){

           $this->token($data);

       }

   }

   $this->load->view('thirdview');

}

public function token($data=array())

{

   $this->load->view('firstview');

   $data['resposeflag'];

   $this->load->view('token',$data);

   $this->load->view('thirdview');

}

以下视图显示了Controller功能之间传递的数据。

    <?php 
echo form_input(array('name'=>'source','readonly'=>'true','value'=>$resposeflag)); 
?>