2014-02-19 39 views
0

自昨天起,我一直在與Laravel 4中的會話相關的問題卡住。我有一個非常簡單的應用程序,它是一個車輛製造商,您以基礎/底盤開始,並且可以添加選項建立你的車輛。我有一個動作看起來像這樣的(寧靜)VehicleController控制器:Laravel 4的會話問題

public function getShow($id) 
{ 
    $excluded_parts = array(); 

    $the_vehicle    = Session::get('the_vehicle'); 
    $the_vehicle_built_image = Session::get('the_vehicle_built_image'); 

    // Check if the selected vehicle changed 
    if ($the_vehicle != $id) { 
     // Forget the previous sessions 
     Session::put('the_vehicle', ''); 
     Session::put('the_vehicle_built_image', ''); 
     Session::put('the_options', array()); 
     ....... 

另一種方法是用來添加選項:

public function getAddopt($id) 
{ 
    // Get the current selected vehicle 
    $the_vehicle = Session::get('the_vehicle'); 

    // Get the current selected vehicle's options 
    $the_options = Session::get('the_options', array()); 

    ........ 

奇怪的行爲是下面的,當我加載vehicles/show/1頁第一次,沒有會話似乎設置,當我嘗試添加一個選項vehicles/addopt/34,我得到一個直接的錯誤已經Session::get('the_vehicle')應該設置在前面的動作是空的。 這個問題發生在第一次加載新鮮的會話(我的意思是我需要關閉/重新打開瀏覽器重現)。 我想念Laravel 4中的會議嗎?

謝謝

+0

我不確定我是否理解這個問題。你在哪裏用'Session :: put'在會話中存儲值?我只看到它試圖忘記前一個會話的一個實例,在這種情況下,您應該對所有項目使用'Session :: forget('the_vehicle');'或'Session :: flush();' 。 –

+0

存儲該值,稍後在'getShow'動作中,這個方法很長,我沒有粘貼整個東西。 「Session :: forget」是正確的,這是我以前使用的,但嘗試調試認爲他們可能是一個問題,我試着用'Session :: put'用空字符串更新' – feub

+0

啊我看到了 - 只是爲了確認,你是否在'Session :: put'之後調用'Session :: save()'? –

回答

0

我很抱歉,如果人們花時間在這個問題上,尤其是亞當,但我發現我的錯誤。這是佈局錯字,我有這個{ URL::to('/') }}注意缺失的第一個花括號。這隻會破壞IE中的會話。 謝謝。