MF. Hujaeri MF. Hujaeri - 2 months ago 8
PHP Question

How to pass a POST value to a function after a redirect in a CodeIgniter controller

I am trying to pass POST data to a function after performing a redirect. This is my code

class mycontroller extends CI_Controller {
function myfunction1(){
$data = array(
'code' => $this->mymodel->myautocode(),
'value1' => $this->input->post('value1'),
);
redirect(mycontrollers/myfunction2);
}

function myfunction2(){
// now, how to pass $data in here
$value2 = $value1
$code1 = $code
}
}


how to pass to myfunction2

Answer

try this code, you have use session for this

function myfunction1(){
    $data = array(
        'code' => $this->mymodel->myautocode(),
        'value1' => $this->input->post('value1')
    );
    $this->session->set_userdata($data);
    redirect(mycontrollers/myfunction2);
}

function myfunction2(){     
    $value2 = $this->session->userdata('value1');
    $code1 = $this->session->userdata('code');
}