最近、ColdFusion 2018 を職場にインストールしましたが、スコープが正しく機能しないことに不満を感じています。いつものように、すべての .cfc を /CFC フォルダーに入れましたが、空白なしでは実行されません。application.cfm
そのフォルダ内のファイル。アプリケーション、プロキシ拡張アプリケーションなどのアプリケーションを拡張しようとしましたが、CFC をルート フォルダーに移動すると、JSON で構文エラーが発生するだけです。過去 2 週間に見つけたすべての記事を読みましたが、スコープが機能しない理由をまだ理解できません。/CFC フォルダー内でセッション変数を設定できるようですが、フォルダー外では使用できませんか? 私は数年間 CF を使用していませんが、自分自身が精通していると考えており、私の人生ではこれを機能させることはできません。木が原因で森を見逃している可能性がありますが、誰かが喜んで手伝ってくれるなら、私は感謝します.
インスタンス化されたオブジェクト。
application.SessionMgr = CreateObject(this.obj,'CFC.SessionMgr').init('session');
プロキシ呼び出し;
cfajaxproxy cfc="CFC/SessionMgr" jsclassname="SessionMgr";
返品は正しいです。
var s = new SessionMgr();
var setReport = s.setValue('ReportID', document.getElementById('cboReportKey').value);
alert(setReport);
ただし、手動で設定してもsession.ReportID = 7
、フォルダーの外では保持されません。
ここはSessionMgr.init
これはinit
;
<cffunction name="init" access="public" returntype="SessionMgr" output="no" hint="I instantiate and return this object.">
<cfargument name="scope" type="string" required="yes">
<cfargument name="requestvar" type="string" default="SessionInfo">
<cfset var scopes = "application,Client,Session">
<cfif Not ListFindNoCase(scopes, arguments.scope)>
<cfthrow message="The scope argument for SessionMgr must be a valid scope (#scopes#)." type="MethodErr">
</cfif>
<cfset variables.scope = arguments.scope>
<cfset variables.requestvar = arguments.requestvar>
<cfset updateRequestVar()>
<cfreturn this>
</cffunction>
そしてsetValue
fn
<cffunction name="setValue" access="remote" hint="I set the value of the given user-specific variable." returntype="string">
<cfargument name="variablename" type="string" required="yes">
<cfargument name="value" type="any" required="yes">
<cfset var val = arguments.value />
<cfset SetVariable("#arguments.variablename#", val) />
<cfset r = Evaluate(arguments.variablename) />
<cfreturn r />
</cffunction>