Reputation: 370
I am trying to get the input values from the view to controller and saving this value as flashdata to use it in the other controller. Now the i am able to store the value until i redirect, but as soon as it comes to redirect, it loses its value. I am not sure whats going over here.
Here is my code below:-
Controller.php
public function first() {
$testing = $this->input->post('fname');
$this->session->set_flashdata('fstname', $testing);
$this->session->keep_flashdata('fstname');
// echo $this->session->flashdata('fstname'); //able to get the flashdata value till here.
redirect('Home/second/'); //but when I am using this, flashdata loses its value
}
public function second() {
$data['getfname'] = $this->session->flashdata('fstname');
$this->load->view('details', $data);
}
View (details.php)
<?php echo $getfname ?>
Output
Null
config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
autoload.php
$autoload['libraries']=array();
Additionally, I also tried using userdata() but its not showing on the second function after redirect.
Thanks for your time.
Upvotes: 1
Views: 994
Reputation: 23
check if Post data is not empty
$testing = $this->input->post('fname');
var_dump($testing);
exit;
you can skip keep_flashdata, you dont need that in that context
Check session setting in config.php
for example:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'mysession';
$config['sess_expiration'] = 86400;
$config['sess_save_path'] = 'sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
check autload.php
:
$autoload['libraries'] = array('session', [...]);
check session flash var directly:
$strFstname = $this->session->flashdata('fstname');
die($strFstname);
Your code should work, I used flashdata like this many times.
Upvotes: 0