UDF file in Model Glue

This has just came up on the MG Lists and I thought i should post my solution on how I implement a UDF file in MG

1)My UDF file is a component (cfc) on the root of the site. Example UDF:

view plain print about
1<cffunction name="getDateTime">
2    <cfreturn now() />
3</cffunction>

2)Then in my controller (in the onRequestStart):

view plain print about
1<!--- Add a UDF --->
2<cfset variables.udf = createObject("component","pathTo.udf").init()>
3<cfset arguments.event.setValue("udf", variables.udf)>

3)On my view page I have

view plain print about
1<!--- Get UDF --->
2<cfset udf = viewState.getValue('udf') />

Then to call a function

view plain print about
1<cfoutput>#udf.getDateTime()#</cfoutput>

Posted: 25-Jan-2006

View: 1896

Permalink: here

Comments

Hi Andy,

Thanks for UDF explanation, what about <cfscript> tags old CF5 functions to get on .cfm pages. Is there any easy solution to put into model-glue where it should be available globally

Thanks

#1 Sana Ullah
25/Jan/06 11:19 AM

I would say that all you had to do was change the function something() section of your UDF's to change them to <cffunction name="something"> and any attribute management stuff.

Then you can keep the rest of the udf pretty much the same.

MD

#2 Mark Drew
25/Jan/06 12:51 PM