With a little side of applesauce...

Monday, January 12, 2009

Coldfusion - init() with arguments, and "this" scope

Ok, I'm not sure why this is, but if I invoke an init() function for my Logger.cfc, my local methods need to be explicitly called with "this":
<cfset cfcLog = createObject("component",".Logger").init("workflow")>
<cfset cfcLog.logger( "this is an error" )>


Here is the error:
Entity has incorrect type for being called as a function.

The symbol you provided file is not the name of a function.


Here is the original function:
<cfcomponent name="Logger" ...    
<cffunction name="logger"
returnType="void"
access="public"
output="no"
hint="log an entry to a log file, send email, or both
@param message string required text of log entry
@param logType string information/warning/error/fatal (default information)
@param action string file/mail/all (log to file, send mail, or both log and send email) (default file)
">
<cfargument name="message" type="string" required="yes">
<cfargument name="logType" type="string" default="Information">
<cfargument name="action" type="string" default="file">

<cfswitch expression = "#action#">
<cfcase value="file">
<cfset file( message, logType )>
</cfcase>

...


And, here is the fix:
<cfcomponent name="Logger" ...    
<cffunction name="logger"
returnType="void"
access="public"
output="no"
hint="log an entry to a log file, send email, or both
@param message string required text of log entry
@param logType string information/warning/error/fatal (default information)
@param action string file/mail/all (log to file, send mail, or both log and send email) (default file)
">
<cfargument name="message" type="string" required="yes">
<cfargument name="logType" type="string" default="Information">
<cfargument name="action" type="string" default="file">

<cfswitch expression = "#action#">
<cfcase value="file">
<cfset this.file( message, logType )>
</cfcase>

...

1 comments:

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

About Me

Shannon Eric Peevey
View my complete profile