I am trying to get the value of the flashdata and userdata from one function to another within the same controller. It seems that I am using redirect in the func A to func B. So when the func loads it does not read the value and becomes Null. I used var_dump() and print_r but the values are null. Please find my sample code as follow:-
Controller: Sample.php
i have declared the session lib at the start
$this->load->library('session');
when tried with $this->session->userdata
public function A {
$city = $this->input->post('Ucity');
$depart = $this->input->post('Udepartment');
$this->session->set_userdata('City',$city);
$this->session->set_userdata('Department',$depart);
//I guess the issue is coming overhere. When it redirects, it loses its values
redirect ('/Sample/B/');
}
public function B {
$getCity = $this->session->userdata('City');
$getDept = $this->session->userdata('Department');
if(isset($getCity)) {
$data['ct'] = $getCity;
$data['dt'] = $getDept;
$this->load->view(header);
$this->load->view(menu);
$this->load->view(fetchEmp, $data);
$this->load->view(footer);
}
else {
var_dump($getCity);
print_r($getCity);
}
}
when tried with $this->session->flashdata
public function A {
$city = $this->input->post('Ucity');
$depart = $this->input->post('Udepartment');
$this->session->set_flashdata('City',$city);
$this->session->set_flashdata('Department',$depart);
$this->session->keep_flashdata('City');
$this->session->keep_flashdata('Department');
//I guess the issue is coming overhere. When it redirects, it loses its values
redirect ('/Sample/B/');
}
public function B {
$getCity = $this->session->flashdata('City');
$getDept = $this->session->flashdata('Department');
if(isset($getCity)) {
$data['ct'] = $getCity;
$data['dt'] = $getDept;
$this->load->view(header);
$this->load->view(menu);
$this->load->view(fetchEmp, $data);
$this->load->view(footer);
}
}
And my fetchEmp.php (view)
<h1>City: <?php echo $ct .'and department: ' . $dt ?></h1>
The output I get is: NULL