可以cfmodule返回值到调用者的本地作用域吗? [英] Can cfmodule return values to caller's local scope?

查看:112
本文介绍了可以cfmodule返回值到调用者的本地作用域吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cfmodule的cfm中,通过使用Caller范围返回值。如果我在CFC中的函数中调用cfmodule,Caller映射到CFC的变量范围正确?

解决方案



是的,对上述所有。示范:



Testing.cfc:

 < cfcomponent> 

< cfset Variables.Instance = {} />

< cffunction name =checkTheScopeYoreturntype =Struct>

< cfset var LOCAL = {} />

<!---调用CFModule --->
< cfmodule template =TestModule.cfm/>

< cfset Variables.theLocal = LOCAL />

< cfreturn Variables />

< / cffunction>
< / cfcomponent>

TestModule.cfm

 < cfif thisTag.ExecutionMode EQend> 

< cfset Caller.FromModule =设置为变量范围/>

< cfset Caller.Instance.FromModule =设置为Variables.instance变量/>

< cfset Caller.Local.FromModule =设置为LOCAL范围/>

< / cfif>

Scribble.cfm:

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

< cfdump var =#theResult#>

转储显示您可以访问函数中的局部变量以及变量整个CFC的范围:

  struct 

CHECKTHESCOPEYO:
[function]
参数:无
返回类型:Struct
角色:
访问:public
输出:
DisplayName:
提示:
描述:
FROMMODULE:设置为变量范围
INSTANCE:
[struct]
FROMMODULE:设置为Variables.instance变量
THELOCAL:
[struct]
FROMMODULE:设置为LOCAL范围
THIS:
[component Testing]
方法:
CHECKTHESCOPEYO
[function]
参数:无
ReturnType:Struct
角色:
访问:public
输出:
DisplayName:
提示:
描述:


Inside the cfm of the cfmodule, values are returned through the use of Caller scope. If I call a cfmodule inside a function in a CFC, Caller maps to the Variables scope of the CFC correct? Can I return the values into to local scope of the CFC function?

Thanks

解决方案

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:  

这篇关于可以cfmodule返回值到调用者的本地作用域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆