【发布时间】:2014-01-01 18:34:33
【问题描述】:
我正在构建一个网站,我在其中遵循 MVC 来管理我的代码,而不使用任何框架。我已将所有查询放入 cfcs 并在我的 Application.cfm 中对其进行初始化,并将它们存储在如下应用程序变量中:
<cfset aplication.customerProfileObject=
createObject("component","cfc.customerprofile").init()>
为了执行任何查询操作,我创建了一个函数,然后像这样在任何地方调用它:
<cfset selectedCustomerOb =
application.customerProfileObject.getContactCustomerProfileDetail(session.userid)>
我不知道是什么导致了问题,但有时用户会访问其他用户的数据。这怎么可能?它是在评估另一个用户的会话数据还是我初始化了 cfc 错误?
应用设置如下:
<cfapplication name="MyDataSourceName"
sessionmanagement="Yes"
setclientcookies="yes"
setdomaincookies="yes"
loginstorage="session"
sessiontimeout="#CreateTimeSpan(0, 2,0,0)#">
CustomerProfile.cfc
<cfcomponent>
<cffunction name="init">
<cfreturn this>
</cffunction>
<cffunction name="getContactCustomerProfileDetail" returntype="query"
description="Returns customer contact details by contactid"
access="public">
<cfargument name="ccId" type="numeric" required="yes">
<cfquery name="getContactCustomerProfileDetail"
datasource="#Application.ds#"
dbtype="ODBC"
username="#Application.UserName#"
password="#Application.Password#">
<!-------My query here--->
</cfquery>
<cfreturn getContactCustomerProfileDetail>
</cffunction>
</cfcomponent>
【问题讨论】:
-
如果
session.userid为空怎么办?您的 CFC 会返回第一条(或全部)customerprofile记录吗? -
你有Skyhook的代码
getContactCustomerProfileDetail() -
听起来 CFC 中没有适当的范围。
-
请贴出customerprofile.cfc的代码
-
如果 session.userid 为空,系统将注销。
标签: coldfusion cfc application.cfm