根据我提供的示例,我希望 index.cfm 显示 hello
我怎样才能做到这一点?
应用程序.cfc
<cfcomponent>
<cfset this.sessionManagement = true />
<cffunction name="onSessionStart">
<cfset SESSION.myVar = "hello">
</cffunction>
</cfcomponent>
索引.cfm
<html>
<head>
<title>Testing</title>
</head>
<body>
<cfoutput>#SESSION.myVar#</cfoutput>
</body>
</html>
我发现当我添加
<cfinvoke component="Application" method="onSessionStart">
到index.cfm它可以工作,但是每次刷新页面时所有变量都会被覆盖。
最佳答案
您需要为您的应用程序命名,例如:
<cfset this.name = "foo">
在您的 Application.cfc 伪构造函数中。否则CF无法创建应用程序,因此无法将 session 与应用程序关联起来。
关于session - 是否可以在 Application.cfc 中设置 session 变量,然后从任何应用程序页面检索它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8051782/