Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > Using UDFs effectively > Specifying the scope of a function Using the Request scope PreviousNext

Using the Request scope

You can effectively manage functions that are used in application pages and custom tags by doing the following:

  1. Define the functions on a function definitions page.
  2. On the functions page, assign the functions to the request scope.
  3. Use a cfinclude tag to include the function definition page on the application page, but do not include it on any custom tag pages.
  4. Always call the functions using the request scope.

This way you only need to include the functions once per request and they are available throughout the life of the request. For example, create a myFuncs.cfm page that defines your functions and assigns them to the Request scope using syntax such as the following:

function MyFunc1(Argument1, Argument2)
{ Function definition goes here }
Request.MyFunc1 = MyFunc1

The application page includes the myFuncs.cfm page:

<cfinclude template="myfuncs.cfm">

The application page and all custom tags (and nested custom tags) call the functions as follows:

Request.MyFunc1(Value1, Value2)

Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > Using UDFs effectively > Specifying the scope of a function Using the Request scope PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.