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

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

问题描述

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

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?

谢谢

推荐答案

是的,以上所有.一个示范:

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

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

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天全站免登陆