Codeigniter 在两个函数/视图之间传递参数

Codeigniter 在两个函数/视图之间传递参数,codeigniter,Codeigniter,我在控制器中有两个函数,分别是step1和step2。我想在主题之间传递$data数组。下面是控制器代码。在步骤1中,我在步骤2中输入了简单的echo,它显示$data['text1'的值。此值在step2控制器中为allays NULL,没有我在step1中键入的仪表。 public $data = array( 'id' => '', 'text1' => '', 'text2' => '' ); p

我在控制器中有两个函数,分别是step1和step2。我想在主题之间传递$data数组。下面是控制器代码。在步骤1中,我在步骤2中输入了简单的echo,它显示$data['text1'的值。此值在step2控制器中为allays NULL,没有我在step1中键入的仪表。
    public $data = array(
        'id' => '',
        'text1' => '',
        'text2' => ''
    );

    public function __construct()
    {
        parent::__construct();
    }

    public function step1()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

        $this->form_validation->set_rules('text1', 'Text 1', 'rquired');
        if($this->form_validation->run() === FALSE)
        {
            $this->load->view('test/step1', $this->data);
        }
        else
        {
            $this->data['text1'] = $this->input->post('text1');
            redirect('test/step2');
        }
    }

    public function step2()
    {
        $this->load->view('test/step2', $this->data);

    }

    public function step3()
    {

    }
}

您通过重定向(“测试/步骤2”)重定向到步骤2;这基本上会重新加载页面,并且$data属性会被清空

相反,您应该尝试以下方法:

$this->data['text1'] = $this->input->post('text1');
$this->step2(); //would call your existing step2() method
如果您真的想让头重定向到像test/step2这样的url,您可能需要将$data存储在会话中