News by ColdFusion Cookbook

This feed does not validate. (details)

How do I create a tag cloud from a query?

22 Nov 07:04
A tag cloud is a list of tags where size and color reflects popularity- the more often a tag is used the larger and perhaps more colorfully it will be displayed in the cloud. Say for example you want to create a dynamic tag cloud of links based on a list of categories that you have stored in a database. Once you have queried your data, the basic idea is to dynamically set the css font-size of your displayed tag text based on how many hits your query returned for that particular tag. The fo...

How do I avoid forgetting to declare local variables?

14 Nov 04:12
It is critical when writing component methods and UDFs that every variable defined in the code is properly var scoped. If you forget this step - the variable will exist outside of the method and could potentially lead to some very hard to debug problems. One way to get around accidentally forgetting to var scope is to create a structure for all the variables. Consider this code block:

How do I return a query from an Excel file?

2 Nov 23:12
NOTE: To use the below solution, your ColdFusion server must allow you to create Java objects. Many shared hosts do not allow this. Java's JDBC ODBC allows you to connect to a Microsoft Excel file. Then using Java's SQL classes we are able to query this file and return certain tables to a ColdFusion query object. This function returns the ColdFusion query object so that you may use the methodology of "Query of Queries" to return the data that you need. A possible location for this funct...

How can an Application.cfc's extend to other Application.cfc's?

20 Oct 05:06
One of the cool things you can do with Application.cfc is to extend it in subdirectories to override behavior for parts of your application. This Tech Note tells you how. Update: there is a way to extend the root Application.cfc without using a mapping. In your root directory, alongside your root Application.cfc, create ProxyApplication.cfc that contains just these two lines:

How can I validate a password to make sure it contains numbers and letters and is at least X characters long?

20 Oct 04:23
Regular expression combined with the <cfif> and reFind() function give you the flexibility to validate against all kinds of requirements. In the following code sample, the password will have to contain at least one letter and number and be between 6-15 positions long.

How do I retrieve the dates for specific days of the week for all months in a year, and put them into an array?

30 Sep 03:32
While there is no ColdFusion specific function to return this, it is possible to build such functionality using ColdFusion's various date functions. Here is a UDF (user-defined function) as well as an example: function getEveryDOW(dowlist) { var year = year(now()); var day1 = ""; var x = ""; var thisDOW = ""; var result = arrayNew(1); var initialDOW = ""; var offset = ""; if(arrayLen(arguments) gte 2) year = arguments[2]; day1 = createDate(year, 1,1);...

How do I end a session when the user closes their browser?

23 Sep 04:17
Use J2EE session variables! Note: useing J2EE session variables, you will notice that your session ends when your close the browser. Actually, your session is not ending. Instead, when you relaunch your browser, a new session is created. Therefore you cannot close your browser as a means to test this code. Instead, you must wait the complete amount of time it takes for sessions to expire in your application. (If not specified, it will default to a value set in the ColdFusion administrator -...

How do I restart an application in ColdFusion?

15 Sep 23:26
There are a few answers to this question. ColdFusion will automatically run the onApplicationStart method the first time your application is accessed. You can run the method manually by inserting some code. The following code could be added to your onRequestStart method to allow for a URL variable to re-init the application. It is important to note though that this will not call the met...

How do I get a listing of just the files or child directories in a directory?

9 Sep 01:45
You can use the cfdirectory tag with the list option, and then there are two ways to only display the directories. The first option is to use <cfif> to filter on 'type': #dirResults.name# The second option is to do a query of queries to filter the results:

How can I pad a variable with spaces or other characters?

6 Sep 00:29
If you need to pad a ColdFusion variable with spaces then you can use the build in rjustify() and ljustify() functions. For example: #newText# If you ever find the need to pad a ColdFusion variable with non-space characters (i.e. Change 'name' to 'name-----'), then the repeatString() function is your friend. For example:
Pages   ← previous   next
1 2 3 4 5