我们可以用等效的 cfscript 语句替换每个 ColdFusion 标签吗?

发布于 2024-11-30 08:23:50 字数 373 浏览 2 评论 0原文

我想知道我的 cfml 页面或 cfc 组件是否可以仅使用 cfscript 标记?

我们可以在任何地方使用它吗?它的使用有什么限制吗?

编辑:

我很好奇,因为我读了以下行

除了变量设置之外,其他操作往往略有不同 在 CFScript 中比在标签中更快。

请在此处阅读

I wanted to know can my cfml page or cfc components with with only cfscript tag?

Can we use it everywhere? Is there any limitation in its usage?

Edit:

I am curious because I read the following line

In addition to variable setting, other operations tend to be slightly
faster in CFScript than in tags.

Read it here

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

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

发布评论

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

评论(3

不喜欢何必死缠烂打 2024-12-07 08:23:50

大多数标签现在都实现为 CFScript 就绪实现,但不是全部。与上一张海报所说的相反,CFMAIL 是已经完成的项目之一: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ff9.html

至于其他脚本覆盖范围,它在文档中:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7feb.html

注意,现在完全可以用脚本编写 CFC:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSE99A664D-44E3-44d1-92A0-5FDF8D82B55C.html

但我会谨慎这样做,因为并非所有标签已在脚本中实现,如果您突然发现您也需要在仅脚本 CFC 中使用其中一个标签...您就有点 卡住。

另外,我认为像 CFQUERY 这样的一些结构是比 Query.cfc 的方法更优雅的解决方案。

至于 CFScript 比基于标签的代码更快的评论,自从 CFMX7.0 中编译器发生变化以来,情况并非如此。大多数情况下,代码现在编译成几乎相同的东西。有些操作在 CFScript 中更快,有些操作在基于标签的代码中更快。也就是说,与调整实际代码或数据库访问或内存处理相比,这些性能提升将是微乎其微的:我不会将基于标签的代码重构为基于脚本的代码来尝试寻找性能提升。

Most tags are now implemented as CFScript-ready implementations, but not all of them. Contrary to what the previous poster said, CFMAIL is one of the ones that has already been done: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ff9.html

As far as the other script coverage goes, it's in the docs:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7feb.html

Note, one can definitely write CFCs entirely in script now:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSE99A664D-44E3-44d1-92A0-5FDF8D82B55C.html

But I would be cautious about doing this because not all tags are implemented in script yet, and if you suddenly find you need too use one of them in your script-only CFC... you're a bit stuck.

Also I think some constructs like CFQUERY are a more elegant solution than Query.cfc's approach.

As for the comment that CFScript is faster than tag-based code, that hasn't really been the case since the compiler changes in CFMX7.0. Mostly the code compiles down to pretty much the same thing now. Some operations are faster in CFScript, some are faster in tag-based code. That said, these performance gains are going to be minimal compared to tuning your actual code or DB access or memory handling: I'd not refactor tag-based code to script-based code to try to find performance gains.

愿与i 2024-12-07 08:23:50

自 CF11 起,所有 cf* cfscript 支持 标签

一般格式是这样的:

<!--- tag version --->
<cfwhatever arg1="val1" arg2="val2" ... />

<!--- script version --->
<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...);
</cfscript>

当你有嵌套标签(即 cfhttp/cfhttpparam)时,格式就像 -

<!--- tag version --->
<cfwhatever arg1="val1" arg2="val2" ...>
  <cfwhateverparam arg3="val3" ... />
</cfwhatever>

<!--- script version --->
<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...) {
    cfwhateverparam(arg3="val3", ...);
  };
</cfscript>

想我记得(虽然我没有找到这方面的文档)一些 cf*如果标签在 CF11 之前已有 cfscript 替代方案,则不支持它们。

用作函数的 CF 标签不会返回值,如果您尝试以这种方式使用它们,将会生成错误:

<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...); //THIS IS OK

  var myresult = cfwhatever(arg1="val1", arg2="val2", ...); //SYNTAX ERROR!

  //generally, this is what you do instead:
  var myresult = '';
  cfwhatever(arg1="val1", arg2="val2", ..., variable="myresult");
</cfscript>

As of CF11, all cf* tags are supported in cfscript.

General format is like this:

<!--- tag version --->
<cfwhatever arg1="val1" arg2="val2" ... />

<!--- script version --->
<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...);
</cfscript>

When you have nested tags (i.e. cfhttp/cfhttpparam), the format is like-

<!--- tag version --->
<cfwhatever arg1="val1" arg2="val2" ...>
  <cfwhateverparam arg3="val3" ... />
</cfwhatever>

<!--- script version --->
<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...) {
    cfwhateverparam(arg3="val3", ...);
  };
</cfscript>

Gotchas

I think I remember (though I haven't found documentation for this) that some cf* tags are not supported if they already had a cfscript alternative prior to CF11.

CF tags used as functions do not return a value, and will generate an error if you try to use them that way:

<cfscript>
  cfwhatever(arg1="val1", arg2="val2", ...); //THIS IS OK

  var myresult = cfwhatever(arg1="val1", arg2="val2", ...); //SYNTAX ERROR!

  //generally, this is what you do instead:
  var myresult = '';
  cfwhatever(arg1="val1", arg2="val2", ..., variable="myresult");
</cfscript>
别挽留 2024-12-07 08:23:50

在 Coldfusion 8 及更低版本中,cfscript 中不提供 cfmail 等标签。但是,您可以通过将其包装在 cffunction 中来调用它们,如下所示:

<cffunction name="myCfEmail">
    <cfmail ...></cfmail>
</cffunction>

<cfscript>
    myCfEmail();
</cfscript>

在 Coldfusion 9 中,您实际上可以对某些标签执行此操作。请参阅 http://www. bennadel.com/blog/1663-Learning-ColdFusion-9-CFScript-Updates-For-Tag-Operators.htm 了解如何执行此操作。

In coldfusion 8 and below tags like cfmail are not avaiable in cfscript. You can however call them by wrapping it in a cffunction like this:

<cffunction name="myCfEmail">
    <cfmail ...></cfmail>
</cffunction>

<cfscript>
    myCfEmail();
</cfscript>

In coldfusion 9 you can actually do this for some tags. See http://www.bennadel.com/blog/1663-Learning-ColdFusion-9-CFScript-Updates-For-Tag-Operators.htm on how to do this.

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