我正在使用 CFWheels 框架 1.1.8 创建一个基于会话的购物车。我遇到了一个奇怪的问题,即 ColdFusion 9 会话不存在。我花了无数个小时检查并仔细检查我的代码。我希望新鲜的眼睛能发现我错过的东西。下面是我的代码的简化版本。任何建议将不胜感激。
配置/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
<cfscript>
if (! StructKeyExists(session, "cart")){
session.cart = arrayNew(1);
}
</cfscript>
控制器/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#">