我们可以用等效的 cfscript 语句替换每个 ColdFusion 标签吗?
我想知道我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数标签现在都实现为 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.
自 CF11 起,所有
cf* cfscript 支持
标签。一般格式是这样的:
当你有嵌套标签(即 cfhttp/cfhttpparam)时,格式就像 -
我
想我记得(虽然我没有找到这方面的文档)一些
cf*
如果标签在 CF11 之前已有 cfscript 替代方案,则不支持它们。用作函数的 CF 标签不会返回值,如果您尝试以这种方式使用它们,将会生成错误:
As of CF11, all
cf*
tags are supported in cfscript.General format is like this:
When you have nested tags (i.e. cfhttp/cfhttpparam), the format is like-
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:
在 Coldfusion 8 及更低版本中,cfscript 中不提供 cfmail 等标签。但是,您可以通过将其包装在 cffunction 中来调用它们,如下所示:
在 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:
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.