|
Yes… thanks for asking. I forgot to do that! My library function is more a feature of SOS, so you would have to see a bit more on SOS to understand that facet. You may have noticed that you cannot “declare” UDFs in the request scope. You can however “reference” or “point” to the udf with a request scope variable. This is how I do it in principle with my UDF libraries. (NOTE: I also declare all my UDFs with a udf_myFuncion() name. This will prevent there being issues with future versions of CF breaking my code because they use the same name I use for any library. It also helps, because it makes the use of UDFs very visible when reviewing code!
In my libraries… I see if the library has been defined… if it has… then I don’t redefine it again. I wish CF had a intelligent include mechanism… so it new the file had already been included… heh, not yet! I will keep it on the wish list. (Would like to have an include that could be managed like a cache, on scope (request, session, application… etc) with ability to refresh it at will. Again… this is my creative solution for UDF Libraries… which is part of my SOS. It would work in principle in any methodology.
Here is a neat snippet you could use also… if you would like to place multiple columns in a select box, this will format columns one at a time to put in the code box. Another MMUG manager found out how to do it… I just whipped this UDF to say thanks for sharing the tip.
John Farrar SOSensible
------------------ <cffunction name="udf_selectColumn"> <cfargument name="content" type="string" required="Yes"> <cfargument name="length" type="numeric" required="yes">
<cfset var local = structNew()>
<cfset local.myReturn = arguments.content & repeatString(" ",arguments.length-len(arguments.content))>
<cfreturn local.myReturn> </cffunction>
<cfset request.udf.selectColumn = udf_selectColumn> -------------------
<cfinclude template=”???”> <html>
<head> <title>test</title> <style type="text/css"> .tester { font-family: "Courier New", Courier, mono; font-size: 12px; color: #000000; } </style> </head>
<body>
<!--- (assumes max length 10 chars for any column) --->
<!--- dummy test columns ---> <cfset ls1="wwwwww,iii,jklmno"> <cfset ls2="ab,xxxx,jklmno"> <cfset ls3="aa,bbbb,cccccccc">
<cfset sp=repeatString(" ",10)>
<form action="" method="post"> <select name="x" class="tester"> <cfloop from=1 to=#Listlen(ls1)# index="x"> <cfoutput> <option value="#x#">#request.udf.selectColumn(listgetAt(ls1,x),20)# #request.udf.selectColumn(left(listgetAt(ls2,x),10)# #listgetAt(ls3,x)#</cfoutput> </cfloop> </select> </form> </body>
</html>
-----Original Message-----
John, can you post a snippet of the code you use to place your UDFs in the request scope? I'd like to see how you accomplished this.
Thanks |
Title: RE: [CFCDev] Function Libraries
- Re: [CFCDev] Function Libraries John D Farrar
- Re: [CFCDev] Function Libraries Joe Rinehart
- RE: [CFCDev] Function Libraries John D Farrar
- Re: [CFCDev] Function Libraries Sean Corfield
- Re: [CFCDev] Function Libraries Joe Rinehart
- RE: [CFCDev] Function Libraries John D Farrar
- RE: [CFCDev] Function Libraries Kevin J. Miller
- RE: [CFCDev] Function Libraries Dawson, Michael
- Re: [CFCDev] Function Libraries Raymond Camden
- RE: [CFCDev] Function Libraries wired
- Re: [CFCDev] Function Libraries Joseph Flanigan
