
22
Chapter 1: Migrating Applications from ColdFusion 5
Using the cfindex tag in ColdFusion MX
To populate a collection with the contents of the query results, you can now use the
cfindex
tag
with the
query
attribute and
type
=
"file"
or
type
=
"path"
, for all actions that require
information from the
key
attribute. You can also still use
type
=
"custom"
.
When you use
type
=
"file"
or
type
=
"path"
with a query, the
action
attribute queries to get
filenames or file paths from the
key
attribute, and passes the query results to its actions. The
actions use the filenames or file paths to execute their code.
The following table shows a sample database for an application on a Windows server:
You can populate a collection using either of the following scripts:
•
Populate the
snippets
collection with files specified in the description column of the
database:
<CFQUERY NAME = "bookquery"
DATASOURCE = "book">
SELECT * FROM book where bookid='file'
</CFQUERY>
<CFOUTPUT QUERY = "bookquery">
#url#,#description# <BR>
<cfindex collection = "snippets" action = "update" type = "file"
query = "bookquery" key = "description" URLPath = "url">
</CFOUTPUT>
•
Populate the
snippets
collection with paths specified in the description column of the
database:
<CFQUERY NAME="bookquery"
DATASOURCE="book">
SELECT * FROM book where bookid='path1' or bookid='path2'
</CFQUERY>
<CFOUTPUT QUERY="bookquery">
#url#,#description# <BR>
<cfindex collection="snippets" action="update"
type="path" query="bookquery" key="description" URLpath="url" >
</CFOUTPUT>
BookID URL
Title
Description
bookid1
url1
title1
description1
bookid2
url2
title2
description2
bookid3
url3
title3
description3
file
http://localhost/cfdocs/snippets
title4
c:\inetpub\wwwroot\cfdocs\snippets\f
ile.cfm
path1
http://localhost/cfdocs/snippets/
title5
c:\inetpub\wwwroot\cfdocs\snippets\
path2
http://localhost/cfdocs/
cfmlsyntaxcheck
title6
c:\inetpub\wwwroot\cfdocs\
cfmlsyntaxcheck