CFC 中的 cfscript 函数默认输出=false 吗?
我认为在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
我并不完全确定,但我的猜测是脚本函数在这方面与 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 neithertrue
norfalse
.Setting the
output
attribute for acffunction
, the following are the case:true
is equivalent to the function being wrapped incfoutput
.false
is equivalent to the function being wrapped incfsilent
.cfoutput
norcfsilent
.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.简短回答:
没关系。
除非您明确地从中调用 writeOutput() ,否则 cfscript 不会输出任何内容。 这包括 cfscript 中的函数以及函数外部的任何 cfscript 代码。
这与 CF 标签的语法不同,默认情况下,CF 标签之间至少输出空格。 在
cfscript
中,您编写的任何文本都将由CFML引擎进行编译。 在 CF 标签中,您编写的任何文本都将写入输出缓冲区并发送到浏览器。长答案:
这与不指定输出属性相同。
cfscript
块不输出任何内容。 任何标记块,除非包含在cfsilent
中,否则都会输出空格。 是的,即使 cffunctions 也会这样做,但如果输出属性设置为 false,则输出将被丢弃。彼得·鲍顿的回答的本质是正确的。 它既不包含在
cfsilent
中,也不包含在cfoutput
中。 输出并不被禁止,但除非您明确执行,否则输出不会发生。您始终可以将基于标签的
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 incfscript
as well as anycfscript
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 incfsilent
, 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
norcfoutput
. 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...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 throughcfscript
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 totrue
, it will output "test
" before returning.