Coldfusion范围澄清 [英] Coldfusion Scopes Clarification

查看:191
本文介绍了Coldfusion范围澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读关于CF Scopes,并对CFC范围及其影响感到舒适(

I have been reading about the CF Scopes, and am comfortable with the CFC scopes and their implications (detailed here), however, whenever I search for CF scopes it almost always references in the context of a CFC - So I was hoping for some clarification around scopes in CFM pages. I am working with CF 9/10 so only really interested in how the scopes behave in these releases.


  1. 在CFM页面上 - CFM页面是否具有与其他地方相同的并发问题,或者是CFM页面上绑定到该特定请求范围的变量?

  1. What scopes are available on a CFM page - do CFM pages have the same concurrency problems as can happen elsewhere, or are the variables scoped on a CFM page bound to the scope of that specific request?

如果我在CFM页面中包含行< cfset myVar = 10 /> ,那么它将包含哪个范围?在访问变量的其他用户或访问该变量的其他cfm页面上是否存在任何其他用户的风险?

If I include the line <cfset myVar = 10 /> in a CFM page , which scope will it be included in? is there any risk of either other users on the same page accessing the variable or other cfm pages accessing it?

推荐答案

除了THIS之外,几乎所有范围都可在CFM页面中找到。

Almost all the scopes except 'THIS' are available in the CFM pages.

在CFM页面中声明的无范围变量可以直接调用,或者可以使用VARIABLES作用域前缀调用。

unscoped variables declared in CFM page can be called directly or can be called with VARIABLES scope prefix.

例如:

<cfset varA = 'someValue'/>

也可以写为

<cfset VARIABLES.varA = 'something' />

对我的知识,除非你创建一个单例(只适用于CFC) ,您从不冒险与其他用户共享变量。

To my Knowledge, unless you create a singleton (only possible for CFC's) and put it in Application scope, you never risk sharing variables with other users. This is also valid if one is not careful about scoping the local variables properly in the CFC functions.

在CFM页面上,每个用户请求都有自己的处理线程,并且永远不会与其他用户请求交叉。因此,变量只绑定到该特定请求的范围。

On a CFM page, each user request has its own processing thread and never gets crossed with other user request. So, the variables are bound only to the scope of that specific request.

如果你想要一个变量被所有请求页面的用户使用,你可以把在APPLICATION范围内。

if you want a variables to be used by all the users requesting a page, you can put that in the APPLICATION scope.

我不太明白你的第二个问题。

I did not quite understand your second question. if you can elaborate on it, may be i can add more to my answer.

更新

此代码将帮助您回答这两个问题。

This code will help you answer the 2 questions.

<cfscript>
    function a(){
        _a = 20;
        WriteOutput("Inside function:"&variables['_a']);
        WriteOutput("Inside function:"&variables['_b']);
    }
    _b = 30;
    a();
    WriteOutput('outside function:'&variables['_a']);
</cfscript>

输出

内部函数:20
内部函数:30
外部函数:20

Inside function:20
Inside function:30
outside function:20

这篇关于Coldfusion范围澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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