|
The Cached Within feature allows you to specify
a time during which ColdFusion server will save
the query results in memory. In this example, the
time spans are shown as all zeros, which represent
days, hours, minutes and seconds, (from left to
right). Thus, ColdFusion server will execute the
query every time a user reqeusts a page which has
the query. You can specify the time during which
query lives in memory by changing the hours to a
1, which would direct ColdFusion server to save
the query in memory for one hour. Now you will
return to the Dreamweaver Tag Chooser to finish
adding required ColdFusion tags for building the
UDF.
- Click the CFML Advanced tab an then the More
Tags option.
- Select the
cfreturn
tag.
- Complete the
cfreturn
tag in the Dreamweaver Code View as shown below:
<cfreturn GetTeams.Teams>
The cfreturn tag defines what the UDF will
return when a page passes information to it.
The cfreturn
requires you to specify information from the
Teams column that you have from the GetTeams
Query; which, in turn is filtered based on
the value of the ID that you passed through
the cfargument tag.
The completed UDF should look like the following
(note that your code may look different if
you changed the Cached Within attribute):
<cffunction name="retrieveit" output="false">
<cfargument name="ID" type="numeric" required="true">
<cfset var GetTeams = "">
<cfquery name="GetTeams" datasource="devnetudf"
cachedwithin="#CreateTimespan(0,0,0,0)#">
SELECT Teams FROM tbl_info
WHERE ID = #ARGUMENTS.ID#
</cfquery>
<cfreturn GetTeams.Teams>
</cffunction>
Browsing the UDF Now you can retrieve data from the UDF very easily.
We can call the information statically, as shown
below:
<cfoutput>#retrieveit(1)#</cfoutput>
You can also browse static.cfm from your browser
(for instance, at http://localhost:8500/dw_udfs/static.cfm).
Note that the server name will vary based on your
setup.
Likewise, you may you may retrieve data from
the database based on a user's form data (where
the information comes from a select list form
control, named selInfo):
<cfoutput>#retrieveit(form.selInfo)#</cfoutput>
You can browse select.cfm through your browser
(for instance, at http://locahost:8500/dw_udfs/select.cfm).
The form action goes to result.cfm. The results
change based on your selection.
Now that you've completed your UDF, you can copy
the code into a separate file and use it as an
include. In this way, you can refer to the UDF
within your pages with minimal code. Check out
my completed sample code download to browse the
completed UDF.
This tutorial taught you how to create a UDF
from within Dreamweaver MX. Check out DevNet
for more information on UDFs. |