如何在CodeIgniter控制器中重定向后将POST值传递给函数

时间:2016-09-28 03:57:13

标签: php codeigniter

我正在尝试在执行重定向后将POST数据传递给函数。这是我的代码

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
    }
}

如何传递给myfunction2

2 个答案:

答案 0 :(得分:1)

尝试此代码,您已使用此会话

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

答案 1 :(得分:0)

class mycontroller extends CI_Controller {
    function myfunction1(){
        $data = array(
            'code' => $this->mymodel->myautocode(),
            'value1' => $this->input->post('value1'),
        );
    return $data;
    }
    function myfunction2(){
        $data = $this->myfunction1();
        $value2 = $data['value1'];
        $code1 = $data['code'];
//perform your operations here
    }
}