Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Reviewing CFScript enhancements

From: ColdFusion 9 New Features

Video: Reviewing CFScript enhancements

A longtime complaint of ColdFusion users who prefer to code using CFScript is that they couldn't do everything they need to do without though jumping out of a CFScript block to use a tag which didn't have a CFScript equivalent. ColdFusion 9 gets us most of the way there by adding a bunch of new functions to the language by creating proxy objects for complex tags such as cfquery and cfmail. In this video, I will demonstrate a few of the new functions that have been added, show you how to find the implementations of ColdFusion9's Proxy Objects, and how do you cfquery and cfmail inside of CFScript and the first few functions we'll take a look at are system-level functions, such as Throw, cfdump, cflock, location and cftrace.

Reviewing CFScript enhancements

A longtime complaint of ColdFusion users who prefer to code using CFScript is that they couldn't do everything they need to do without though jumping out of a CFScript block to use a tag which didn't have a CFScript equivalent. ColdFusion 9 gets us most of the way there by adding a bunch of new functions to the language by creating proxy objects for complex tags such as cfquery and cfmail. In this video, I will demonstrate a few of the new functions that have been added, show you how to find the implementations of ColdFusion9's Proxy Objects, and how do you cfquery and cfmail inside of CFScript and the first few functions we'll take a look at are system-level functions, such as Throw, cfdump, cflock, location and cftrace.

These all now have their own functions and what would normally be attributes on the tag have now become arguments to a function. So the first thing I'll do is demonstrate the writedump function. In your Chapter3 folder, open up cfscript.cfm and I just have a blank CFScript block that we are trying to use for our testing inside of this video. So I am going to create a new object or rather a new structure and instead of using a cfdump, we'll do writedump and I'll say var = Person, Label ="My Person Structure" and we'll preview the file.

And here we see a dump just like we would if we used cfdump. While that's not terribly exciting from a demonstration point of view, this makes it a whole lot easier to debug your code inside of a CFScript block. Normally you would have to close the CFScript block, put your dump in and then open it so that you can continue processing your code. So let's take a look at the next batch of functions. This group of tags that have bodies, such as cflock, cfthread, and cftransaction. For these you will call the function and provide braces to show the start and stop of the action.

So I will demonstrate the lock function, the CFScript equivalent to cflock. Let's comment at our previous code and now I'll use the new lock function. We will specify a timeout at ten seconds and tell it which scope we want to lock, in this case the Application scope. Now you can see I am also getting code hints in CF Builder to name the lock, set my throwontimeout, and then specify a type readOnly or exclusive. I will just leave things as they are for now.

Open my closing braces, and it will close them automatically for me. And then inside here I can do whatever I want inside that lock. And that's all there is to using the tags with bodies. The other functions in this group, thread and transaction, have sibling functions that you'll use within the parent function. So inside the transaction function, you can use transactionCommit and transactionRollback, instead of calling the cftransaction tag with a separate action. The next group of tags is tags without bodies.

In this case, we're calling a function and specifying arguments but we don't have a body to wrap code in like we do with the previous group. So in this case, I will show you how to use the param function versus cfparam. Let's once again comment out our code. So we are going to create a new param function and we will say that this parameter is going to be numeric and FORM.id and we'll set it's default value to 2. Just to make sure this works, we'll go ahead and writedump our FORM scope, and preview our file.

And here you can see it's defined id with the default value of 2. Our last batch of functions aren't really functions. Instead they are complex objects, which are used to replace the functionality of cfquery, cfmail, cfftp and other tags that have more complex interaction. So to show you how to work these, I am first going to show you where you can find them in ColdFusion's Component browser. So in the browser, we will go to our ColdFusion Administrator, CFIDE directory and in the componentutils directory, we will go to componentdoc.cfm.

On the left-hand side, scroll down until you find com.adobe.coldfusion. Click that link and down here, you'll see each of the new objects that are used to replace an existing ColdFusion tag. If I click on query, we can see we have a large number of methods we can use. You can use this Component browser to figure out how to use each of the new proxy objects inside ColdFusion 9. For now I am going to show you how to use the query object.

So let's once again comment out our code and I will start by creating a new query object. So I will say myQuery = new Query(). Now that I have that object, I can start setting properties about the query that I want to run. First we will do myQuery.setDatasource and tell it that we want to use the cfartgallery data source. Next I will set the query that I want to run. So we will setSQL(SELECT * FROM Artists).

And now I can execute my query and assign the result to a variable. So, Artists = myQuery.Execute. I writedump Artists. You can see I get a complex result object back. The result object has a result property, which contains my query. It also has some prefix information that gives me the SQL that was executed, the record count and I have a number of methods that I can use on that object.

The most important one is GetResult. So we will go back to the source code and I will dump Artists.getResult. And that gives me back a regular query, just as I would receive if I use the cfquery tag. Now I can do more with the CFQuery, for example, using query params. If I wanted to select only a specific artist, I can do SELECT * FROM Artists where ArtistID = the :ArtistID keyword.

I can then set a parameter for that particular keyword. I will use myQuery.addParam. I am going to specify the artistID parameter, give it a value, and a cfsqltype for validation purposes. Now if I run this code again, I will get a single record back from the database. Cfmail works the same. Let's comment out the query and I will show you how to use the cfmail object.

Let's do myMail = New Mail(). But instead of setting each of these values individually, I am going to use the setAttributes function that's available to all of these objects. So myMail.setAttributes and then I will provide a structure that has all of the configuration for this particular e-mail I want to send. We will say to = dan@sitedriveinc.com from dan.short@gmail.com, subject = "Testing new CFScript objects".

I will set the body of the e-mail and then all I have to do to send my e-mail is myMail.send. So as you can see with the addition of new functions and objects available to CFScript, you can get one step closer to building an entire ColdFusion application with nothing but CFScript.

Show transcript

This video is part of

Image for ColdFusion 9 New Features
ColdFusion 9 New Features

36 video lessons · 2904 viewers

Daniel Short
Author

 
Expand all | Collapse all
  1. 4m 30s
    1. Welcome
      53s
    2. Using the exercise files
      3m 37s
  2. 7m 48s
    1. Adding managing and comparing servers
      5m 26s
    2. Monitoring server health
      2m 22s
  3. 22m 10s
    1. Setting the default data source and SMTP
      5m 6s
    2. Getting programmatic debugging and exception handling
      5m 54s
    3. Reviewing the new onCFCRequest method
      5m 29s
    4. Using ApplicationStop()
      2m 24s
    5. Working with Server.cfc and onServerStart
      3m 17s
  4. 17m 45s
    1. Using ternary and chained operations
      5m 46s
    2. Using New and Import
      4m 2s
    3. Reviewing CFScript enhancements
      7m 57s
  5. 20m 23s
    1. Building with implicit getters and setters
      4m 26s
    2. Working with LOCAL scope in functions
      4m 35s
    3. Serializing objects
      6m 6s
    4. Writing components in CFScript
      5m 16s
  6. 19m 27s
    1. Getting started with ORM
      5m 51s
    2. Logging ORM activity
      2m 13s
    3. Saving objects to the database
      6m 10s
    4. Defining table relationships
      5m 13s
  7. 16m 59s
    1. Caching page fragments
      5m 29s
    2. Managing the cache
      4m 48s
    3. Working with in-memory files using VFS (RAM disks)
      6m 42s
  8. 12m 39s
    1. Working with Excel spreadsheets
      4m 56s
    2. Working with Word documents
      4m 4s
    3. Working with PowerPoint presentations
      3m 39s
  9. 28m 58s
    1. Loading Google maps with markers onto a page
      4m 53s
    2. Adding a Flash movie with the built-in FLV player
      2m 14s
    3. Using multi-file upload control
      6m 7s
    4. Building a progress indicator
      3m 37s
    5. Working with accordion layouts
      3m 18s
    6. Showing information with data grid enhancements
      5m 1s
    7. Informing users with Confirm Alert and Prompt dialog boxes
      3m 48s
  10. 9m 8s
    1. Accessing IMAP accounts
      6m 31s
    2. Working with the new array functions
      2m 37s
  11. 15s
    1. Goodbye
      15s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed ColdFusion 9 New Features.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.