2014-02-15 40 views
0

我正在用CFWheels框架1.1.8創建一個基於會話的購物車。我遇到了一個奇怪的問題,ColdFusion 9會話沒有持續。我花了無數小時檢查,並仔細檢查我的代碼。我希望新鮮的眼睛能夠發現我錯過的東西。以下是我的代碼的簡化版本。任何建議將非常感激。ColdFusion會話問題

配置/ app.cfm

<cfscript> 
    this.name = hash(getDirectoryFromPath(getCurrentTemplatePath()) 
        , "SHA-256"); 
    this.applicationTimeout = createTimeSpan(0, 2, 0, 0); 
    this.loginStorage = "session"; 
    this.sessionManagement = true; 
    this.sessionTimeout = createTimeSpan(0, 1, 0, 0); 
    this.setClientCookies = false; 
    this.setDomainCookes = false; 
</cfscript> 

活動/ onRequestStart.cfm

​​

控制器/ Cart.cfc

<cfcomponent extends="Controller"> 

    <cffunction name="index">  
    </cffunction> 

    <cffunction name="create"> 
     <cfset arrayAppend(session.cart, structNew())> 
     <cfset index = arrayLen(session.cart)> 
     <cfset session.cart[index].title = "Product Name"> 
     <cfset session.cart[index].quantity = "1"> 
     <!--- 
      this return the expect cart array with product. 
      The item disappears once it gets redirected to the index page 
     ---> 
     <cfdump var="#session.cart#" abort> 

     <cfset redirectTo(action="index")> 
    </cffunction> 
</cfcomponent> 

查看/車/ index.cfm

<!--- this return an empty array (same in all other web page)---> 
<cfdump var="#session.cart#"> 

回答

0

我得到它通過在config/app.cfm註釋掉(this.setClientCookies = false;)工作。

0

更改setClientCookies = true只是簡單地使用cookie來跟蹤會話。爲了在不使用cookie的情況下使用會話管理,您需要使用Application.cfc將applicationTapout設置爲application.cfm或onSessionStart。如果你想讓它正確運行,或者對於任何人在這篇文章中遇到困難,我將包括一些鏈接。 Ben用例子解釋Application.cfc做得很好。

Bens Tutorial