什么时候应该在 CFML 中使用自定义标签?
实施 CFML 自定义标记有哪些常见用例(不是 CFX 标签)?在我三年的 CF 经验中,我从未写过一篇。请有人告诉我,在哪种用例/情况下,人们会选择自定义标签而不是 cfc / udf?
What are some common use cases for implementing CFML Custom Tag (not CFX tag)? In 3 yrs of my CF exp I've never written one. Would someone please enlighten me, under which use case / situation would one choose custom tag over cfc / udf?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请记住,自定义标签曾经是可用于扩展 CFML 的唯一方法(直到版本 4) - UDF 出现较晚(CF 5),CFC 出现较晚(CF MX)。它们不再像以前那样常用,原因很简单,因为有更多的选择。
自定义标签本质上基本上是一种语言的过程性语言,随着 CFC 的使用,这种语言在实践中变得越来越面向对象。这是它们不太常见的另一个原因。
但在某些情况下它们仍然会派上用场(但从来都不是必需的)——主要用于界面工作。创建开始状态和结束状态的能力肯定会派上用场。一个简单的例子是页面内容的“包装器”,开始标签可能添加 HTML 标题和页面导航,而结束标签将添加页脚并结束页面。
这样你的页面内容可能只不过是:
当然还有其他方法可以做到这一点 - 但有时经典仍然有价值。 ;^)
Remember that custom tags were, at one time, the only method available to extend CFML (up until version 4) - UDFs came later (CF 5) and CFCs later still (CF MX). They're not as commonly used as they once were for the simple reason that there are more options.
Custom tags are basically procedural in nature in a language that, with CFCs, become more and more OO in practice. This is another reason that they're not very common.
But there's still cases where they come in handy (but are never required) - mostly for interface work. The ability to create both a start and end state can definately come in handy. A simple example could be a "wrapper" for page content the opening tag might add the HTML header and page navigation while the closing tag would add the footer and end the page.
In this way your page content could be nothing more than:
Of course there are other ways to do this as well - but sometimes the classics still have value. ;^)
查看 CFUniform 项目,了解自定义标签使用的一个很好的示例。自定义标签在为应用程序的 UI 部分构建可重用部分时非常有用。
Look at the CFUniform project for a great example of custom tag usage. Custom Tags are great when building reusable pieces for the UI portion of an application.
我认为,在大多数情况下,自定义标签大多已被半途而废,因为 UDF、CFC 以及与 Java(以及较小程度的 .NET)的集成允许更简单、更直接的方法来完成类似的事情。
回顾我刚开始接触CF5的时候,我能想到几个例子。 CFX)Zip 是一个不错的选择,它允许与 Zip 文件进行交互,之前可以直接通过 CF 进行交互。
在更现代的环境中,我能想到的唯一用途是提供不是用 Java 或 .NET 编写的预编译代码,例如用 C 编写的专有小玩意。不过,这是一个相当小众的用途。
老实说,我想在这一点上它们比其他任何东西都存在更多或向后兼容性。
I think that, for the most part, custom tags have mostly fallen by the wayside since UDFs, CFCs, and integration with Java (and to a lesser degree .NET) allowed easier and more straightforward ways to do similar things.
Looking back to when I started in CF5, I can think of several examples. A good one might be CFX)Zip, which allowed interaction with Zip files before that was available directly through CF.
The only use I can think of offhand in a more modern context would be to provide precompiled code that wasn't written in Java or .NET, such as proprietary doodads written in C. That's a pretty niche use, though.
Honestly, I imagine at this point they exist more or backwards comatibility than anything else.
自从 CFC 出现以来,我就不再使用自定义标签,只是因为开销太大。他们需要很长时间才能启动和执行。但就像 @Jim Davis 所说,当您需要编写一个包含其他内容的标签时,它们可能很有用。
但在一个定义明确的解决方案中,您可以将它们全部结合在一起。
Ever since CFCs came out I've stopped using custom tags simply because of the overhead. They take too long to initiate and execute. But like @Jim Davis said, they may be useful where you need to write a tag that wraps around other content.
But in a well defined solution, you can do way with them all together.