2016-03-25 33 views
-1

我只需要20分钟。对于这一目的,我使用到TempData在笨笨:会议TempData的是在会话中删除破坏

在页面上显示的一些数据其实TempData的是会话数据,我将其标记为使用mark_as_temp方法

一个TempData的下面是我的代码

public function final_result() 
    { 
    //make the session data as tempdata  
     $this->session->mark_as_temp(
      array('hotel_basic','user_ht_bk_data','hotel_info','hotel_search_query','booking_response','ht_star_rating','each_rooms'),1200  
     );  
     //after marking as tempdata destroy the original sessiondata 
     $this->session->sess_destroy(); 
    //read from the tempdata 
     $data['result']=$this->session->tempdata('user_ht_bk_data'); 

     $this->view('final-view',$data); 
    } 

$data['result']将返回空值。

根据codeigniter文档sess_destroy()永远不要删除tempdata。

但在我的情况下,tempdata执行session_destroy

+0

哪个版本你使用 - 当前文档中表示:值到期后,或会话过期或被删除,该值被自动删除。 看@:https://www.codeigniter.com/user_guide/libraries/sessions.html#tempdata 所以如果你销毁会话的价值将被删除 – sintakonte

+0

CI版本3.0.3 –

+0

@shammon啊你是运行PHP 7 ? – MackieeE

回答

-1

这是因为数据被作为TempData的必须在会议上已经退出预先设定时被删除。作为stated in the documentation你需要尝试类似:

$_SESSION['user_ht_bk_data'] = 'Test string'; // Or use set_tempdata with $this->session->set_tempdata('user_ht_bk_data', 'Test string', 300); 
$this->session->mark_as_temp('user_ht_bk_data', 1200); // No need to use this if you used set_tempdata(); 
$this->session->sess_destroy(); 
$data['result']=$this->session->tempdata('user_ht_bk_data'); 
+0

同样的事情是我使用的唯一区别是'mark_as_temp'中的一个参数是一个数组 –

+0

我看不到您的代码添加会话数据。请发布所有相关代码,其他地方可能会有影响。 – Technoh

1

一旦使用sess_destroy(),所有的会话数据(包括flashdata和TempData的)将永久破坏和相同的请求过程中的功能将不可用在销毁会话后,您可以使用

Destroying a Session In Codeigniter

解决方案

  1. 显示最终结果为平常(在无会话销毁),并 countdown with JavaScript在20个薄荷糖破坏会议。
  2. Use cookies
+0

好吧那么我该如何解决我的问题 –

+0

@shammon检查回答 –

+0

让我试试:) –