cfmodule可以将值返回给调用者的本地范围吗?

Hen*_*nry 5 coldfusion cfc

在cfmodule的cfm中,通过使用Caller范围返回值.如果我在CFC中的函数内调用cfmodule,调用者映射到CFC的变量范围是否正确?我可以将值返回到CFC函数的本地范围吗?

谢谢

Dan*_*ort 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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Scribble.cfm:

<cfset theResult = CreateObject("component", "Testing").checkTheScopeYo() />

<cfdump var="#theResult#">
Run Code Online (Sandbox Code Playgroud)

转储显示您可以访问函数中的局部变量,以及整个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:  
Run Code Online (Sandbox Code Playgroud)