how to pass a variable from one controller to the other in Code igniter

后端 未结 6 919
攒了一身酷
攒了一身酷 2021-02-05 21:25

I have just started learning Code Igniter .

I want to know how can I pass a variable from one controller(first_cont.php) to other controller (second_cont.php) ?

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 22:09

    If you are using session in the first controller then dont unset that session in first controller, instead store the value which you want in the other controller like,

    $sess_array = array('value_name1' => 'value1', 'value_name2' => 'value2');
    $this->session->set_userdata('session_name', $sess_array);
    

    then reload this session in the other controller as

    $session_data= $this->session->userdata('session_name');
    $any_var_name = $session_data['value1'];
    $any_var_name = $session_data['value2'];
    

    this is how you can pass values from one controller to another....

提交回复
热议问题