我正在尝试将 flashdata 值从一个函数获取到同一控制器中的另一个函数。一旦我使用 redirect() 它就会失去它的价值并显示为空。我尝试同时使用 flashdata 和会话数据,但没有任何效果。请在下面找到我的代码:-
public function getUserDetails()
{
$first_name = $this->input->post('Uname');
$last_name = $this->input->post('Ulname');
//having an insert query
//I tried with session
$this->session->set_userdata('fName_sess', $first_name);
$this->session->set_userdata('lName_sess', $last_name);
//I tried with flashdata
$this->session->set_flashdata('fName_flash', $first_name);
$this->session->set_flashdata('lName_flash', $last_name);
//I am inserting the value in the database table and $uid is the PK
redirect('/User/person/'.$uid);
}
public function person()
{
//with session
$fN_sess = $this->session->userdata('fName_sess');
$lN_sess = $this->session->userdata('lName_sess');
//with keep_flashdata
$fN_flash = $this->session->keep_flashdata('fName_flash');
$lN_flash = $this->session->keep_flashdata('lName_flash');
//also tried with flashdata
$fN_flash = $this->session->flashdata('fName_flash');
$lN_flash = $this->session->flashdata('lName_flash');
echo 'Value with session'. $fN_sess . $lN_sess . '<br>';
echo 'Value with Flash' . $fN_flash . $lN_flash ;
//i have all my views loaded here
}
我不确定为什么在重定向后它没有从一个函数获取值到另一个函数。
在此先感谢您的时间。
更新:
public function getUserDetails(){
$first_name = $this->input->post('Uname');
$last_name = $this->input->post('Ulname');
//set input post to flash data
$this->session->set_flashdata('fName_flash', $first_name);
$this->session->set_flashdata('lName_flash', $last_name);
redirect('/User/person/');
}
public function person(){
$fname = $this->session->flashdata('fName_flash');
$lname = $this->session->flashdata('lName_flash');
if(isset($fname)){ // check if the flash data fname is set. you can do that to lname also.
$this->load->view(page_header);
$this->load->view(page_menu);
$this->load->view(Details);
$this->load->view(page_footer);
}
查看页面(Details.php):
<h1> Welcome <?php echo $this->session->flahdata(fName_flash).' ' . $this->session->flahdata(lName_flash) ; ?> </h1>
我在这里看到了一个帖子,上面写着为 sesson 创建一条路径(点击这里)。
这是我的 config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
//$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE; // change this
$config['sess_match_ip'] = TRUE; // change this
$config['sess_match_useragent'] = TRUE; // change this
$config['cookie_prefix'] = '';
$config['cookie_domain'] = 'http://'. $_SERVER['HTTP_HOST'] ;
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;