Web News

Small business websites on way out?
Mom-and-pop type of small business websites that fail to catch up with latest internet technology would be extinct by the end of 2007, blogging expert Gobala Krishnan predicts...

Bankers see rate regime to remain
Bankers do not expect any major changes in key interest rates by the Reserve Bank in its quarterly review of the monetary policy on October 31...

Polaris net up at Rs 27 cr
Polaris Software Lab Ltd has reported a net profit of Rs 27.10 crore on revenue of Rs 255.56 crore for the quarter ended September 2006, compared to a net profit of Rs 13.25 crore on revenue of Rs 213.55 crore for the same period last year...




10.17.06


How To Actually Use A UDF?

By Raymond Camden

Over the past few days I've had multiple people ask me the same question - and that means one thing to me... blog post!

The question these people were asking was the same - I know how to write a UDF, but not sure how to actually use it on a page? By that they didn't mean the "function" syntax (x = foo()), but how to include the UDF so that it could be used on a page.

The answer is simple once you realize that a UDF is nothing more than another kind of ColdFusion variable. Consider this code:

<cfoutput>
#x#
</cfoutput>


What do you have to do to make this not throw an error? There are multiple ways to handle this. First, define it on the page:

<cfset x = "DJ Jazzy Jeff and the Fresh Prince">
<cfoutput>#x#</cfoutput>


Another way:

<cfinclude template="thisiswherexismade.cfm">
<cfoutput>#x#</cfoutput>


Web CEO 6.0

There are other ways of course, but you get the idea. So to use a UDF you follow the same rules. Here are two more examples using the same format as above:

<cfscript>
function cic() { return "monkey"; }
</cfscript>
<cfoutput>#cic()#</cfoutput>


And then the cfinclude version:

<cfinclude template="filewithcfcUDFinit.cfm">
<cfoutput>#cic()#</cfoutput>


Just like other variables, UDFs can be placed in the shared scopes. You can't do it directly though but rather must reassign:

<cfscript>
function dharma() { return "swan"; }
request.dharma = dharma;
</cfscript>

<cfoutput>#request.dharma()#</cfoutput>


Comment

About the Author:
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



About DevWebPro India
DevWebPro India is for professional developers ... those who build and manage applications and sophisticated websites. DevWebPro India delivers via news and expert advice New Strategies In Development.

DevWebPro India is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com NetworkNewz.com


-- DevWebPro India is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


New Strategies In Development DevWebPro India News Archives About Us Feedback DevWebPro India Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact