coldfusion

tech2024-01-02  72

coldfusion

The ColdFusion 9 beta is finally here, and there’s plenty to get excited about. If you’re up to a challenge, test your knowledge of what’s new in ColdFusion with our quiz! What’s more, there’s a freebie up for grabs for the first 200 quiz contestants who enter their details – a ColdFusion evangelist’s kit, full of everything you need to know about what’s happening in the world of ColdFusion.

ColdFusion 9 Beta终于来了,有很多令人兴奋的地方。 如果您有挑战, 请通过我们的测验测试您对ColdFusion的新知识! 更重要的是,前200名参加测验的参赛者可以免费获得他们的详细信息-ColdFusion传教士的工具包,其中包含您需要了解的有关ColdFusion世界正在发生的一切的全部信息。

ColdFusion and the ColdFusion Markup Language (CFML) in general have recently gained significant traction, with not one but two alternative engines garnering interest from the open source community; now, interest is growing more, with the next generation of Adobe ColdFusion – formerly known as Centaur – made available as a public preview release. This pre-release version of ColdFusion 9 has unveiled a very interesting set of new features.

总体而言,最近ColdFusion和ColdFusion标记语言(CFML)受到了广泛的关注,其中有两个替代引擎引起了开源社区的关注,其中不乏一种替代引擎。 现在,人们的兴趣与日俱增,下一代Adobe ColdFusion(以前称为Centaur)作为公共预览版本提供。 此预发布版本的ColdFusion 9推出了一组非常有趣的新功能。

Among these are improvements to various tags, the CFScript language and the overall syntax and coding style, the PDF subsystem, and Ajax components. Probably the two most publically discussed and awaited features are the ColdFusion IDE ColdFusion Builder (also known by its codename, Bolt) and ColdFusion 9’s new ORM (object-relational mapping) system. We’ll be taking a look at some code examples – if you’re keen to follow along, you can grab all these here, and view demos in action. Let’s dive in!

其中包括对各种标记的改进,CFScript语言以及整体语法和编码样式,PDF子系统以及Ajax组件。 可能是两个公开讨论最久的功能,即ColdFusion IDE ColdFusion Builder(也称为代号Bolt)和ColdFusion 9的新ORM(对象关系映射)系统。 我们将看一些代码示例–如果您热衷于继续学习,可以在这里获取所有内容,并观看实际演示 。 让我们潜入吧!

Caution! The features described in this article and all code samples are based on the ColdFusion 9 pre-release version available on Adobe Labs at the time of publishing. Please understand that Adobe might change or even remove features of pre-release software at any time – so some features in this article may be dropped from the final release.

警告! 本文介绍的功能和所有代码示例均基于发布时Adobe Labs上可用的ColdFusion 9预发行版本。 请理解,Adobe可能随时更改甚至删除预发布软件的功能-因此本文中的某些功能可能会从最终版本中删除。

A big kudos goes to Kay Smoljak for contributing the sections and examples on ORM and Ajax features to this article.

Kay Smoljak对本文的ORM和Ajax功能部分和示例做出了很大的贡献,这是一个很大的荣誉。

ColdFusion生成器 (ColdFusion Builder)

Let’s start this article off with a look at one of the most visible features of the upcoming ColdFusion 9 release: ColdFusion Builder. Although ColdFusion Builder 9 is a stand-alone product and separate from the ColdFusion 9 server product itself, we think it’s one of the most important moves Adobe has made in the last few years. ColdFusion veterans might remember back to the good old days of Allaire’s ColdFusion Studio, which was the last commercially available and dedicated ColdFusion IDE.

让我们从即将开始的ColdFusion 9版本最明显的功能之一开始: ColdFusion Builder。 尽管ColdFusion Builder 9是独立产品,并且与ColdFusion 9服务器产品本身分开,但我们认为这是Adobe过去几年中最重要的举措之一。 ColdFusion的资深人士可能会回想起Allaire的ColdFusion Studio的美好时光,这是最后一个商业上可用的专用ColdFusion IDE。

ColdFusion Builder has been created on top of Eclipse, the well-known development framework that powers dozens of popular IDEs. Adobe’s made good use of Eclipse in the past – Flex Builder (now called Flash Builder) and Flash Catalyst are both Eclipse-based tools.

ColdFusion Builder已在Eclipse之上创建,Eclipse是为数十个流行的IDE提供支持的著名开发框架。 Adobe过去充分利用了Eclipse – Flex Builder(现在称为Flash Builder)和Flash Catalyst都是基于Eclipse的工具。

The IDE presents itself with a typical Eclipse-like workspace consisting of various views. In the figure below, you’ll see a common development setup comprising a project navigator on the left, code views in the center, and multiple helper views such as outline, RDS database and file server views, and log file access to the right.

IDE为自己提供了一个典型的类似于Eclipse的工作区,其中包含各种视图。 在下图中,您将看到一个常见的开发设置,其中包括左侧的项目导航器,中央的代码视图以及多个帮助程序视图(例如,大纲,RDS数据库和文件服务器视图),以及右侧的日志文件访问权限。

It’s possible to set up multiple servers in ColdFusion Builder so that one could directly interact with development, staging, and production environments. The code views also offer toolbars for quick access to commonly used ColdFusion tags, HTML, and CSS features.

可以在ColdFusion Builder中设置多台服务器,以便一台服务器可以直接与开发,登台和生产环境进行交互。 代码视图还提供工具栏,用于快速访问常用的ColdFusion标签,HTML和CSS功能。

ColdFusion Builder includes a line debugger, which developers already working with Eclipse will become familiar with in a very short amount of time. It’s a feature Adobe had already introduced in ColdFusion 8, but now springs to new life with a dedicated IDE catering for the debug process. Here’s the debugger in action.

ColdFusion Builder包含一个行调试器,已经在使用Eclipse的开发人员将在很短的时间内熟悉它。 这是Adobe在ColdFusion 8中已经引入的功能,但现在通过专用于调试过程的专用IDE崭露头角。 这是运行中的调试器。

The third set of features we’d like to introduce here are the extremely helpful code and content assistance, together with syntax checking. Any good IDE should include syntax highlighting and code completion as a matter of course, but Adobe has added useful support for instantiating ColdFusion Components (CFCs) and introspecting CFC methods, which you’ll see in action in the figures below.

我们想在这里介绍的第三组功能是非常有用的代码和内容帮助以及语法检查。 当然,任何好的IDE都应包括语法突出显示和代码完成功能,但是Adobe已添加了对实例化ColdFusion组件(CFC)和自省CFC方法的有用支持,您将在下图中看到它们。

ColdFusion Builder also provides an ongoing syntax analysis of your code by parsing the files right there in the IDE. This feature alone provides a massive boost in productivity – there’s no more need to run the page in the browser anymore to see if there was a syntax error in the ColdFusion code.

ColdFusion Builder还可以通过在IDE中解析文件的方式对代码进行持续的语法分析。 仅此功能一项就可以极大地提高生产率–不再需要在浏览器中运行该页面来查看ColdFusion代码中是否存在语法错误。

Of course, there’s more to ColdFusion 9 than a shiny new IDE. Let’s move onto some server features and practical examples.

当然,ColdFusion 9不仅具有闪亮的新IDE。 让我们继续一些服务器功能和实际示例。

语言规范增强 (Language Specification Enhancements)

Let’s examine some of the changes and improvements to the language of ColdFusion itself. The first of these improvements surrounds CFScript, and the changes can be best described as upgrading CFScript to be a first-class citizen in ColdFusion 9. CFScript is a way to write CFML code in a manner that resembles JavaScript. Unfortunately CFScript never supported the full language features of ColdFusion, and was quite limited in a various ways.

让我们研究一下ColdFusion本身的语言的一些更改和改进。 这些改进中的第一个围绕CFScript,而这些更改可以最好地描述为将CFScript升级为ColdFusion 9中的一流公民。CFScript是一种以类似于JavaScript的方式编写CFML代码的方式。 不幸的是,CFScript从未支持ColdFusion的全部语言功能,并且以各种方式受到了很大的限制。

In ColdFusion 9, we’re now able to code ColdFusion Components entirely in CFScript, and that we can run SQL queries from CFScript. To compare, let’s see an identical logging component written and called in both CFML and CFScript. Using CFML, let’s create a simple logging component:

在ColdFusion 9中,我们现在可以完全在CFScript中编码ColdFusion组件,并且可以从CFScript运行SQL查询。 为了进行比较,让我们看看在CFML和CFScript中编写和调用的相同的日志记录组件。 使用CFML,让我们创建一个简单的日志记录组件:

<cfcomponent>  <cffunction name="init" output="false" access="public"     returntype="logWithTags">      <cfargument name="logFile" default="customLogger"        type="string" required="no"/>      <cfset variables.logFile = arguments.logFile />      <cfreturn this/>    </cffunction>    <cffunction name="write" output="false" access="public"     returntype="void">      <cfargument name="message" type="string" required="yes"/>      <cfset writelog(text=arguments.message, file=variables.logFile)/>    </cffunction>   </cfcomponent>

Here’s how we’d invoke the component and write a message to that log:

这是我们调用组件并将消​​息写入该日志的方式:

<cfinvoke component="logWithTags" method="init"  logFile="LogTestDeleteMe" returnvariable="logger" />   <cfinvoke component="#logger#" method="write"    message="Testing out the new logger with CFML." />  

In ColdFusion 9, we’re able to use CFScript for this purpose. Here’s a logging component written in CFScript, which is functionally identical to the above component:

在ColdFusion 9中,我们可以为此使用CFScript。 这是一个用CFScript编写的日志记录组件,其功能与上述组件相同:

component  {      public log function init (string logFile="customLogger") output="false"        {        variables.logFile = arguments.logFile;        return This;        }      public void function write(string message) output="false"      {      writelog(text=arguments.message, file=variables.logFile);      }    }

And in CFScript, we’d invoke it like so:

在CFScript中,我们将这样调用它:

<cfscript>  logger = new log('LogTestDeleteMe');    logger.write("Testing out the new logger.");   </cfscript>

Let’s explore how to execute a database query from ColdFusion 9’s new CFScript engine. If you’re a Java developer, you’ll see how similar the structure of the code is to writing Java code for querying SQL databases via JDBC. The argument passed in the method setDataSource is a named reference to an SQL database that can be set up in ColdFusion’s administration tool:

让我们探索如何从ColdFusion 9的新CFScript引擎执行数据库查询。 如果您是Java开发人员,则将看到代码结构与编写Java代码以通过JDBC查询SQL数据库有多么相似。 在setDataSource方法中传递的参数是对SQL数据库的命名引用,可以在ColdFusion的管理工具中对其进行设置:

<cfscript>  query = new Query();    query.setDataSource('cfartgallery');    query.setSQL("SELECT * from artists") ;    results = query.Execute().getResult();   </cfscript>   <cfdump var="#results#">

Other language enhancements include a cffinally tag for exception handling, the ability to nest cftransaction tags, assignment chaining (a=b=c=d, and so on), and support for ternary operators such as a = (b<c)?b:c.

其它语言增强包括一个cffinally标签进行异常处理,能够将窝cftransaction标签 ,分配链接( a=b=c=d三元运营商,等等),以及支持诸如a = (b<c)?b:c 。

ColdFusion 9 also offers new integration with PDF documents and spreadsheets. The updated PDF subsystem provides new tools for extracting text from PDFs, and optimizing them. The latter is particularly interesting: PDF documents are often full of bookmarks, comments, JavaScript, and other information, but in many use cases it’s best to strip out this extra data.

ColdFusion 9还提供了与PDF文档和电子表格的新集成。 更新后的PDF子系统提供了用于从PDF提取文本并对其进行优化的新工具。 后者特别有趣:PDF文档通常到处都是书签,注释,JavaScript和其他信息,但是在许多用例中,最好去掉这些多余的数据。

Extracting text from a PDF document is as simple as using the cfpdf tag’s new action, extracttext. Here, we’ll extract the text from a test document:

从PDF文档中提取文本就像使用cfpdf标记的新动作extracttext一样简单。 在这里,我们将从测试文档中提取文本:

<cfpdf action="extracttext"  source="#ExpandPath('./testdocument1.pdf')#"    name="xTestdoc"  />

Similarly, using the new optimize action, we can remove the bookmarks and comments from a PDF, and write the results out to a new, optimized file:

同样,使用新的optimize操作,我们可以从PDF中删除书签和注释,并将结果写到新的优化文件中:

<cfpdf action="optimize"  source="#ExpandPath('./testdocument1.pdf')#"    destination="#ExpandPath('./testdocument1_optimised.pdf')#"    nobookmarks = true    nocomments = true />

Another very interesting opportunity to integrate with external data formats has been created with the cfspreadsheet tag. It provides a way to interact with Excel documents of both .xls and .xlsx types, and enables developers to read data from and write data to spreadsheets. The code below reads data from an Excel 2007 document and outputs the content in a table:

与外部数据格式集成的另一个非常有趣的机会是使用cfspreadsheet标签创建的。 它提供了一种与.xls和.xlsx类型的Excel文档进行交互的方法,并使开发人员能够从电子表格读取数据或将数据写入电子表格。 下面的代码从Excel 2007文档中读取数据,并将内容输出到表格中:

<cfset XLSfile = "#ExpandPath('.')#/authorData.xlsx" />   <cfspreadsheet action="read" src="#XLSfile#"      sheet="1" query="excelQuery" headerrow="1" />   <table>    <tr>      <th>First Name</th>      <th>Last Name</th>      <th>Words written</th>    </tr>    <cfoutput query="excelQuery" startrow="2">    <tr>      <td>#firstName#</td>      <td>#lastName#</td>      <td>#wordsWritten#</td>    </tr>    </cfoutput>   </table>

ColdFusion’s SpreadsheetAddRow function allows you to create a new entry in an Excel file. ColdFusion 9 also supports OpenOffice spreadsheets:

ColdFusion的SpreadsheetAddRow函数使您可以在Excel文件中创建一个新条目。 ColdFusion 9还支持OpenOffice电子表格:

<cfset XLSfile = "#ExpandPath('.')#/authorData.xlsx" /> <cfspreadsheet action="read" src="#XLSfile#" name="excelObj" />   <cfset SpreadsheetAddRow(excelObj,"Diane,Sieger,654,2",3,1) />   <cfspreadsheet action="write" name="excelObj" filename="#XLSfile#" overwrite="true" />
ColdFusion ORM (ColdFusion ORM)

One of the most exciting new features in ColdFusion 9 is ColdFusion ORM. ORM stands for object-relational mapping – a concept in object oriented programming where code objects are mapped to relational database tables for persistent storage. The ORM lets you access and update data through the application using the object model, without you needing to know anything about the details of the underlying database structure. The idea is that the ORM takes care of all the mundane, rote tasks for the programmer: scripting tables, writing CRUD operations (create record, update, and delete – the basic building blocks of most applications) and the like, leaving them to focus on interesting and challenging programming tasks. Other advantages of an ORM include database vendor independence and built-in caching features. Sounds good, right?

ColdFusion 9中最令人兴奋的新功能之一是ColdFusion ORM 。 ORM代表对象关系映射–面向对象编程中的一个概念,其中代码对象被映射到关系数据库表以进行持久存储。 使用ORM,您可以使用对象模型通过应用程序访问和更新数据,而无需了解有关基础数据库结构的详细信息。 这个想法是,ORM负责为程序员处理所有平凡而繁琐的任务:脚本编写表,编写CRUD操作(创建记录,更新和删除–是大多数应用程序的基本构建块)等,使它们集中精力从事有趣而富挑战性的编程任务。 ORM的其他优点包括数据库供应商独立性和内置的缓存功能。 听起来不错吧?

ColdFusion developers writing object oriented applications have been able to use ORMs in the past with the help of external frameworks, Transfer and Reactor being the two best known. However, ColdFusion 9’s new built-in ORM features are based on Hibernate, an open source ORM library that has been around in the Java world since around 2004. It’s popular, tried, and tested, and seeing as ColdFusion is based on Java, an obvious choice for the ColdFusion team.

过去,编写面向对象应用程序的ColdFusion开发人员已经能够在外部框架的帮助下使用ORM, Transfer和Reactor是最著名的两个。 但是,ColdFusion 9的新内置ORM功能基于Hibernate , Hibernate是开放源ORM库,该库自2004年左右开始在Java世界中广泛使用。它经过流行,尝试和测试,并且看到ColdFusion基于Java, ColdFusion团队的明显选择。

So how does it work? There are two ways to work with ORM systems: either you create your data objects in code, and let the ORM create the database tables for you, or you start with the database, and have the data objects built for you. ColdFusion ORM lets you work in both of these ways.

那么它是怎样工作的? 使用ORM系统有两种方法:要么用代码创建数据对象,然后让ORM为您创建数据库表,要么从数据库开始,并为您构建数据对象。 ColdFusion ORM可让您以这两种方式工作。

As a very basic example, if you would like ColdFusion to create your tables for you, you’d enable ColdFusion ORM in your Application component by setting some basic variables. Let’s say you were using a MySQL data source that had been set up in the ColdFusion Administrator as sampledb:

作为一个非常基本的示例,如果您希望ColdFusion为您创建表,则可以通过设置一些基本变量在Application组件中启用ColdFusion ORM。 假设您使用的是在ColdFusion Administrator中设置为sampledbMySQL数据源:

<cfset this.ormenabled="true"> <cfset this.datasource="sampledb">     <cfset this.ormsettings={Dialect="MySQL"}>

Next, you create your CFC, setting the value of persistent to true to map the CFC to a database table. This example CFC has two properties – name and email:

接下来,创建CFC,将persistent的值设置为true以将CFC映射到数据库表。 此示例CFC具有两个属性- name和email :

<cfcomponent persistent="true">  <cfproperty name="Name">      <cfproperty name="Email">     </cfcomponent>

Now, you can use the ORM functions such as EntityLoad and EntitySave to retrieve and update that data.

现在,您可以使用ORM函数(例如EntityLoad和EntitySave来检索和更新该数据。

When your application is run, if that table does not exist in the database, it will be created. If, on the other hand, you already have a database structure and would like ColdFusion to generate your code, you’re going to need ColdFusion Builder to inspect your database and generate code. If you’d prefer to maintain some control over the way ColdFusion creates that code, that’s okay too – you can create your own base templates to dictate how the generated code should be arranged, or download and install another’s templates.

运行您的应用程序时,如果该表在数据库中不存在,则会创建该表。 另一方面,如果您已经具有数据库结构并希望ColdFusion生成代码,则将需要ColdFusion Builder来检查数据库并生成代码。 如果您希望对ColdFusion创建该代码的方式保持某种控制,那也可以–您可以创建自己的基本模板来指示如何安排生成的代码,或者下载并安装其他模板。

Ajax功能 (Ajax Features)

One of the more exciting updates to ColdFusion 8 was the addition of new Ajax components, making the power of the ExtJS and YUI JavaScript libraries available to the ColdFusion programmer via a few simple tags. Now, in ColdFusion 9, the Adobe team has upped the ante, upgrading all of the libraries (including bringing ExtJS from version 1.0 to 3.0), which brings a number of enhancements across the board.

对ColdFusion 8而言,最令人激动的更新之一是添加了新的Ajax组件,使ExtJS和YUI JavaScript库的功能可以通过一些简单的标签提供给ColdFusion程序员。 现在,在ColdFusion 9中,Adobe团队提高了赌注,将所有库升级(包括将ExtJS从1.0版升级到3.0版),从而全面增强了许多功能。

In particular, the datagrid and accordion components have been updated, and new components include a multiple file upload tool, a progress indicator widget, a media player control, and a Google Maps widget.

特别是,datagrid和手风琴组件已更新,新组件包括多文件上传工具,进度指示器小部件,媒体播放器控件和Google Maps小部件。

At its simplest, the multiple file upload component created with the new cffileupload tag requires only the url attribute, which specifies the processing script that will handle the file upload on the server:

简单来说,使用新的cffileupload标签创建的多文件上传组件仅需要url属性,该属性指定将处理服务器上文件上传的处理脚本:

<cffileupload url="ProcessFiles.cfm">

Below, you’ll see how that upload component appears.

在下面,您将看到该上传组件的显示方式。

There are many configuration options available, including limiting the size, maximum number, and type of files to be uploaded, as well as the button labels, size, and color of the component.

有许多可用的配置选项,包括限制大小,最大数量和要上载的文件类型,以及按钮标签,组件的大小和颜色。

The new cfmediaplayer tag plays video files in the now ubiquitous Flash video format (.flv). Again, a very simple implementation needs only one parameter: the location of the file to play:

新的cfmediaplayer标记以现在无处不在的Flash视频格式(.flv)播放视频文件。 同样,一个非常简单的实现只需要一个参数:播放文件的位置:

<cfmediaplayer source="sample.flv">

Configuration options include height, width, the ability to define borders and a background color, choice to display video controls and allowing the video to be played full screen, and even JavaScript functions to be triggered on load, on start, and on complete. Here’s how a basic media player appears:

配置选项包括高度,宽度,定义边框和背景颜色的能力,显示视频控件的选择以及允许视频全屏播放,甚至在加载,启动和完成时触发JavaScript函数。 基本媒体播放器的显示方式如下:

One very useful Ajax component is the new cfmap widget, which embeds a Google map. The Google Maps API key for the domain can be specified either in the ColdFusion Administrator, in the site’s Application.cfc file, or imported at runtime via the cfajaximport tag. It’s as easy as this:

一个非常有用的Ajax组件是新的cfmap小部件 ,该小部件嵌入了Google地图。 可以在ColdFusion管理器中,站点的Application.cfc文件中指定域的Google Maps API密钥,也可以在运行时通过cfajaximport标记导入。 就这么简单:

<cfajaximport params="#{googlemapkey='YOUR API KEY'}#"> <cfmap centeraddress="345 Park Avenue, San Jose, CA, USA" zoomlevel="8"></cfmap>    

This produces the following map:

这将产生以下地图:

You’ll notice cfmap has an opening and closing tag. Inside the tag pair, you can place cfmapitem tags to represent other items. Let’s add one to point out Adobe’s head office:

您会注意到cfmap有一个开始和结束标记。 在标签对内,您可以放置cfmapitem标签来代表其他项目。 让我们添加一个以指出Adobe的总部:

<cfajaximport params="#{googlemapkey='YOUR API KEY'}#"> <cfmap centeraddress="San Jose, CA, USA" zoomlevel="6">      <cfmapitem name="marker01"       address="345 Park Avenue, San Jose, CA, USA"       tip="Adobe's Head Office"/>     </cfmap>

Now, your map will display the additional marker, as shown below:

现在,您的地图将显示其他标记,如下所示:

Altogether, the preview release of ColdFusion promises to be a highly interesting piece of technology for web developers. There are so many more new features and improvements to the product that we found it impossible to discuss each in detail, or even mention them all here, but you’ll find plenty of information about ColdFusion 9 in the new Administrator’s Guide and CFML reference documentation. The ColdFusion 9 and ColdFusion Builder betas are available, too – now’s the time to start work!

总而言之,ColdFusion的预览版有望成为Web开发人员非常感兴趣的技术。 产品还有更多的新功能和改进,我们无法对每个功能进行详细讨论,甚至无法在此处进行全部提及,但是您会在新的《管理员指南》和CFML参考文档中找到有关ColdFusion 9的大量信息。 。 同时也提供ColdFusion 9和ColdFusion Builder beta版-现在该开始工作了!

ColdFusion 9’s packed with new features and improvements. Test your knowledge of what’s inside the new ColdFusion with our quiz! Don’t forget, the first 200 participants who fill in their details will receive a shiny new ColdFusion evangelist’s kit – perfect for convincing your boss to give ColdFusion a try!

ColdFusion 9包含新功能和改进。 通过测验,测试您对新ColdFusion内部内容的了解! 别忘了,前200名填写详细信息的参与者将获得一个崭新的ColdFusion传教士工具包-非常适合说服您的老板尝试一下ColdFusion!

翻译自: https://www.sitepoint.com/whats-new-coldfusion-9/

coldfusion

最新回复(0)