在cfmodule的cfm中,通过使用Caller范围返回值。如果我在CFC中的函数内调用cfmodule,调用者映射到CFC的变量范围是否正确?我可以将值返回到CFC函数的本地范围吗?
由于
答案 0 :(得分:7)
是的,对于以上所有。演示:
<强> Testing.cfc:强>
<cfcomponent>
<cfset Variables.Instance = {} />
<cffunction name="checkTheScopeYo" returntype="Struct">
<cfset var LOCAL = {} />
<!--- Call a CFModule --->
<cfmodule template="TestModule.cfm" />
<cfset Variables.theLocal = LOCAL />
<cfreturn Variables />
</cffunction>
</cfcomponent>
<强> TestModule.cfm:强>
<cfif thisTag.ExecutionMode EQ "end">
<cfset Caller.FromModule = "Set to the Variables scope" />
<cfset Caller.Instance.FromModule = "Set to the Variables.instance variable" />
<cfset Caller.Local.FromModule = "Set to the LOCAL scope" />
</cfif>
<强> Scribble.cfm:强>
<cfset theResult = CreateObject("component", "Testing").checkTheScopeYo() />
<cfdump var="#theResult#">
转储显示您可以访问函数中的局部变量,以及整个CFC的变量范围:
struct
CHECKTHESCOPEYO:
[function]
Arguments: none
ReturnType: Struct
Roles:
Access: public
Output:
DisplayName:
Hint:
Description:
FROMMODULE: Set to the Variables scope
INSTANCE:
[struct]
FROMMODULE: Set to the Variables.instance variable
THELOCAL:
[struct]
FROMMODULE: Set to the LOCAL scope
THIS:
[component Testing]
Methods:
CHECKTHESCOPEYO
[function]
Arguments: none
ReturnType: Struct
Roles:
Access: public
Output:
DisplayName:
Hint:
Description: