Can cfmodule return values to caller's local scope?

纵饮孤独 提交于 2019-11-30 21:03:19

Yes, to all of the above. A demonstration:

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#">

The dump shows you that you have access to the local variables within the function, as well as the variables scope of the entire 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:  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!