Reputation: 619
I have two functions in controller named step1 and step2. I want to pass $data array between theme. Below is controller code. In step1 i have input in step2 i have simple echo which shows value of $data['text1']. This value is allays NULL in step2 controller, no meter what I type in 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()
{
}
}
Upvotes: 1
Views: 369
Reputation: 1249
You're redirecting to step2 by redirect('test/step2'); That basically reloads the page and your $data property gets emptied.
Instead, you should try something like that:
$this->data['text1'] = $this->input->post('text1');
$this->step2(); //would call your existing step2() method
If you actually want to have a header redirect to url like test/step2 , you may need to have your $data stored in a session.
Upvotes: 2