Can't find function

30 views
Skip to first unread message

manaus

unread,
Dec 24, 2012, 5:10:19 AM12/24/12
to ra...@googlegroups.com
Hello, 
merry christmas eve everybody!

Still tapping on the keyboard for amusement, I came across this problem (bear with me): 
I have a include in the onRequestStart method of Application.cfc. This includes 'functions.cfm'. 
Functions.cfm includes a list of udfs, among these: 

<cfscript>
public function put(required string theString)
{
return writeoutput(theString);

}
</cfscript>

Still, the caller template raises this error: No matching function [PUT] found
The file is loaded for sure, but the function seems still transparent. Same with other functions. 

Thanks guys

Igal Sapir

unread,
Dec 24, 2012, 5:16:00 AM12/24/12
to Railo List

Does it work if you include functions.cfm in the script that's called instead of onRequestStart() ?

--
typos, misspels, and other weird words brought to you courtesy of my mobile device.

Igal Sapir

unread,
Dec 24, 2012, 5:27:35 AM12/24/12
to Railo List

Here's what I recommend:

Convert functions.cfm to functions.cfc -- simply rename the file and wrap with cfcomponent tag.

Then in onApplicationStart(), create an object of functions.cfc and assign it to an application scope variable, e.g

  <cfset Application.functions = new functions()>

Then wherever you want to call a function simply write something like:

  <cfset Application.functions.put( "Hello" )>

HTH,

Igal

--
typos, misspels, and other weird words brought to you courtesy of my mobile device.

On Dec 24, 2012 2:10 AM, "manaus" <max.n...@gmail.com> wrote:

manaus

unread,
Dec 24, 2012, 5:49:30 AM12/24/12
to ra...@googlegroups.com
Thanks Igal!
at your first question, yes, if included at file level it works. 
Now I'm gonna try your solution, although I'd rather take something to keep me more lazy :)

manaus

unread,
Dec 24, 2012, 5:57:32 AM12/24/12
to ra...@googlegroups.com
Igal, 
now it works, thanks!
Just wondering, why didn't before? I have a couple of websites where it works perfectly. Now could be the latest version (mine is 4.0.2) something changed? 

Adam Cameron

unread,
Dec 24, 2012, 6:09:29 AM12/24/12
to ra...@googlegroups.com
This stands to reason. The functions in the include have been loaded into the variables scope of the Application.cfc instance, whereas the "mainline" code has its own variables memory space.

onRequestStart() runs at the beginning of a request (well: towards the beginning of the request), but it's just an event handler, and is run like any other CFC method, so whatever it does "happens" within the scope of the CFC instance, not the code calling the CFC method itself.

If you had an onRequest() interceptor, then you could run the request within the Application.cfc instance's memory space, a side-effect of which would be that the functions you load into its variables scope would also be accessible to your mainline code's variables scope because it'd be the same one. I'm not recommending this though, just pointing it out.

As Igal suggested, I would created CFCs rather than UDF libraries, and stick instances of the CFCs into the application scope.  At the same time, I'd stop to think about whether the UDFs could be more sensibly grouped into multiple CFCs (StringUtils.cfc, MathUtils.cfc), or even use them as proper objects rather than util CFCs. The best fit might be just a monolithic util CFC, but perhaps not. You cited laziness as a factor in how you do this coding: dispense with that notion. Write it properly.

--
Adam

Igal @ getRailo.org

unread,
Dec 24, 2012, 3:00:44 PM12/24/12
to ra...@googlegroups.com
glad it worked.  I doubt that it worked in previous versions.  see Adam's comment which explains this in more details.


Igal
Reply all
Reply to author
Forward
0 new messages