How to redirect to the same page with data in codeigniter

Ravi Rajindu picture Ravi Rajindu · May 25, 2014 · Viewed 12.3k times · Source

I want to redirect to the same page with data array.

$this->load->view('view_name',$data);  

like this how can I refresh the same page with data. please help ?

Answer

tomexsans picture tomexsans · May 25, 2014

You can use flashdata for that.

$data = array(
  'data1' => 'value',
  'data2' => 'value'
);

$this->session->set_flashdata('mydata',$data);
redirect('controller');

check data the data on your controller by.

var_dump($this->session->flashdata('mydata'));

http://www.codeigniter.com/userguide2/libraries/sessions.html