• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

UDF question

LEGEND ,
Sep 08, 2006 Sep 08, 2006

Copy link to clipboard

Copied

I'm trying to create a function that writes actions to a log file. I can do
this manually, but I think it would be easier to do it once and call it when
I need it.

I have:

<cffunction name="LogEntry">
<cfargument name="Mode" required="yes" type="string">
<cfset LogFileInfo="#CreateLogDate# #CreateLogTime# - #Arguements.Mode# has
been created for email address: #form.Email#">
<cffile action="append"
file="c:\Inetpub\wwwroot\serenity\Logs\UserAccounts.txt"
output=#LogFileInfo# addNewLine="yes">
</cffunction>

And I'm calling it using:
<cfoutput>#LogEntry(URL.Mode)#</cfoutput>

I keep getting a error saying that 'Element MODE is undefined in
ARGUEMENTS.'

Can anyone point me in the right direction as to what I'm doing wrong?

Thanks!


TOPICS
Advanced techniques

Views

289

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 08, 2006 Sep 08, 2006

Copy link to clipboard

Copied

As a matter of reuse I would replace all the global and scoped variables in your functions with arguments or create them internally. E.g.:

<cfargument name="Mode" required="yes" type="string">
<cfargument name="EmailAddress" required="yes" type="string">
<cfargument name="LogFileInfo" required="yes" type="string">

<cfset var CreateLogDate = DateFormat(Now(), "mm/dd/yyyy">
<cfset var CreateLogTime= TimeFormat(Now(), "hh:mm:ss tt">

When you have global variables, form varaibles and other scoped variables in your function you are not encapsulating your function, you are making it dependent on the existance of these variables. This is turn will cause headaches with reusing this function as well cause potential bugs.

In any regard you may want to look into the tag <cflog> which does alot of writing the log for you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 08, 2006 Sep 08, 2006

Copy link to clipboard

Copied

change arguements to arguments

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 08, 2006 Sep 08, 2006

Copy link to clipboard

Copied

Is there a way to add a <cfif> to the mix? If I make the cffunction
something like:

<cffunction name="LogEntry">
<cfargument name="Mode" required="no" type="string">
<cfset LogFileInfo="#CreateLogDate# #CreateLogTime# - #Arguments.Mode# has
been created for email address: #form.Email#">
<cffile action="append"
file="c:\Inetpub\wwwroot\serenity\Logs\UserAccounts.txt"
output=#LogFileInfo# addNewLine="yes">
</cffunction>

Since the arguement isn't required, I'd like to test to see if there is a
value there. If not, I'll use a different value in the cfset.....

Can this be done? If so, are you using <cfif> on Argument.Mode???

"Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
news:edt89t$7qs$1@forums.macromedia.com...
> change arguements to arguments
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2006 Sep 09, 2006

Copy link to clipboard

Copied

LATEST
You can use either cfif or cfparam with the arguments scope exactly the same way you use it for any other scope.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation