CFC 中的 cfscript 函数默认输出=false 吗?

发布于 2024-07-24 05:38:58 字数 142 浏览 3 评论 0原文

我认为在 cfscript 中定义为函数的 CFC 方法默认情况下是 output=false,但是当我在 cfcexplorer.cfc 中打开 CFC(浏览器直接访问 CFC)时,它显示输出:已启用。

cfcexplorer.cfc 的 Bug?

I thought CFC's methods defined as functions in cfscript are output=false by default, but when I open the CFC in cfcexplorer.cfc (browser directly to the CFC), it says Output: enabled.

cfcexplorer.cfc's Bug?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愁以何悠 2024-07-31 05:38:59

cfscript 函数是一只奇怪的猴子。 他们两者都是。 您无法指定它们是output="false",但在您使用writeOutput() 之前它们都是这样,但它们由cfcexplorer 报告为output="true"。 我认为 cfml 咨询委员会现在正在考虑这是一个奇怪的问题。

cfscript functions are a weird monkey. They are kind of both. You can't specify that they are output="false", but they are until you use a writeOutput(), but they are reported by cfcexplorer as being output="true". It is an odd issue I think the cfml advisory committee is looking at right now.

佼人 2024-07-31 05:38:59

我并不完全确定,但我的猜测是脚本函数在这方面与 cffunction 标签相同 - 因为默认值既不是 true 也不是

cffunction 设置 output 属性,情况如下:

  • true 相当于将函数包装在 cfoutput 中代码>.
  • false 相当于将函数包装在 cfsilent 中。
  • 保留默认值(未定义)相当于既不使用 cfoutput 也不使用 cfsilent 包装的标准代码。

但是,我几乎从不使用 cfscript,而且实际情况可能并非如此 - 我们必须等待其他人来确认或纠正这一点。

I'm not entirely certain, but my guess would be that script functions are the same as cffunction tags in this regard - in that the default is neither true nor false.

Setting the output attribute for a cffunction, the following are the case:

  • true is equivalent to the function being wrapped in cfoutput.
  • false is equivalent to the function being wrapped in cfsilent.
  • Leaving it default (undefined) is equivalent to standard code that is wrapped neither with cfoutput nor cfsilent.

However, I almost never use cfscript, and this may not actually be the case - we'll have to wait for others to come along and either confirm or correct this.

眼眸里的快感 2024-07-31 05:38:58

简短回答
没关系。

除非您明确地从中调用 writeOutput() ,否则 cfscript 不会输出任何内容。 这包括 cfscript 中的函数以及函数外部的任何 cfscript 代码。

这与 CF 标签的语法不同,默认情况下,CF 标签之间至少输出空格。 在cfscript中,您编写的任何文本都将由CFML引擎进行编译。 在 CF 标签中,您编写的任何文本都将写入输出缓冲区并发送到浏览器。

长答案
这与不指定输出属性相同。

cfscript 块不输出任何内容。 任何标记块,除非包含在 cfsilent 中,否则都会输出空格。 是的,即使 cffunctions 也会这样做,但如果输出属性设置为 false,则输出将被丢弃。

彼得·鲍顿的回答的本质是正确的。 它既不包含在 cfsilent 中,也不包含在 cfoutput 中。 输出并不被禁止,但除非您明确执行,否则输出不会发生。

您始终可以将基于标签的 cffunction 与脚本结合起来,以获得两全其美的效果。 类似...

<cffunction name="x" output="false" access="package">
    <cfargument name="y" type="string" required="false" default="YY" />
    <cfscript>
        var someValue = y & "something";
        writeOutput("test"); // this will not be written
        return someValue;
    </cfscript>
</cffunction>

这可以让您在 cffunction 标记上指定输出和访问,并允许参数是可选的(这是您无法通过 cfscript 函数实现的) ,然后用 cfscript 填充正文,包括 var 语句和函数返回。

当然,对于该函数,如果您删除 output 属性或将其更改为 true,它输出“test”返回之前。

Short answer:
It doesn't matter.

cfscript does not output anything unless you explicitly call writeOutput() from it. This includes functions in cfscript as well as any cfscript code outside of a function.

This is different from CF tags' syntax, which, by default, output at least whitespace between the tags. In cfscript, any text you write will be compiled by the CFML engine. in CF tags, any text you write will be written to the output buffer and sent to browser.

Long answer:
It's the same as not specifying an output attribute.

cfscript blocks don't output anything. Any tag blocks, unless wrapped in cfsilent, do output whitespace if nothing else. Yes, even cffunctions do, but the output is discarded if the output attribute is set to false.

The essence of Peter Boughton's answer is correct. It's neither wrapped in cfsilent nor cfoutput. Output is not forbidden, but it doesn't happen unless you do it explicitly.

You can always combine a tag-based cffunction with scripting to get the best of both worlds. Something like...

<cffunction name="x" output="false" access="package">
    <cfargument name="y" type="string" required="false" default="YY" />
    <cfscript>
        var someValue = y & "something";
        writeOutput("test"); // this will not be written
        return someValue;
    </cfscript>
</cffunction>

This lets you specify an output and access on the cffunction tag as well as allow arguments to be optional (which you can't do through cfscript functions), then fill the body with cfscript, including var statements and the function return.

Of course, for that function, if you remove the output attribute or change it to true, it will output "test" before returning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文