4 Replies - 6052 Views - Last Post: 06 August 2009 - 12:41 PM Rate Topic: -----

#1 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Using CFReturn

Post icon  Posted 03 April 2009 - 06:27 AM

I am trying to call a returned variable from a function but I am new to usin CFC's so I don't know how to.

weekview.cfm
<!---Set the parameters for the current year, month, and time--->
<cfparam name="currentyear" default="#year(now())#">
<cfparam name="currentmonth" default="#month(now())#">
<cfparam name="currentday" default="#day(now())#">
<cfparam name="currenttime" default="#timeformat(now(),'HH:mm')#">
<cfset currentdate = dateformat(createdate(currentyear,currentmonth,currentday))>

<cfinvoke component="week" method="weekstartat">
	<cfinvokeargument name="date" value="#currentdate#">
</cfinvoke>

<table cellpadding="0" cellspacing="0" width="100%">
	<tr><th colspan="7"><cfoutput>#dateformat(createdate(currentyear,currentmonth,currentday),"mmmm d, yyyy")#</cfoutput></th></tr>
	<tr valign="top">
		<cfloop from="1" to="7" index="i">
				<th valign="top"><cfoutput>#dayofweekasstring(i)#</cfoutput></th>
		</cfloop>
	</tr>
	<tr>
		<cfloop from="1" to="7" index="i">
			<td height="50" align="center">All Day Appointments</td>
		</cfloop>
	</tr>
	<tr>
		<td><cfoutput>#weekstartat#</cfoutput></td>
	</tr>
</table>



week.cfc
<cfcomponent>
<!---WeekStartAt Function--->
<cffunction name="weekstartat" access="public" hint="Function to get the date of the first day of the week.  Pass any date in the argument.">
	<cfargument name="date" default="#now()#">
	
	<cfset weekday = dayofweek(date)>
	<cfset subtract = weekday - 1>
	
	<cfset weekstartat = dateadd("d",- subtract,date)>
		
	<cfdump var="#weekstartat#">
	<cfreturn weekstartat />
</cffunction>
</cfcomponent>


I am new to using CFC's so I am doing something wrong.

This post has been edited by xheartonfire43x: 03 April 2009 - 07:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using CFReturn

#2 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Using CFReturn

Posted 03 April 2009 - 09:21 AM

Use the "returnVariable" attribute to capture the value.

<cfinvoke component="week" method="weekstartat" returnVariable="yourVariableName">
	<cfinvokeargument name="date" value="#currentdate#">
</cfinvoke>



It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.

<cffunction name="weekstartat" access="public" hint="Function to get the date of the first day of the week.  Pass any date in the argument.">
	<cfargument name="date" default="#now()#">
	<!--- VAR scope variables. All VAR statements must be at the top of the function --->
	<cfset var weekday = dayofweek(date)>
	<cfset var subtract = weekday - 1>
	<cfset var weekstartat = dateadd("d",- subtract,date)>
	   
	<cfreturn weekstartat />
</cffunction>
</cfcomponent>



Was This Post Helpful? 0
  • +
  • -

#3 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Using CFReturn

Posted 05 April 2009 - 06:11 PM

View Postsansclue, on 3 Apr, 2009 - 08:21 AM, said:

Use the "returnVariable" attribute to capture the value.

It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.


Thanks. Like I said I am just starting with CFC's. I apprenticed under someone who works with ColdFusion 5 so I have been building on what I have learned from him really. Is there any good sites that you know of to learn building and using CFC's?
Was This Post Helpful? 0
  • +
  • -

#4 apendrag0n3  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 03-May 09

Re: Using CFReturn

Posted 04 May 2009 - 11:16 AM

Go to: http://www.coldfusio...i.com/index.cfm

and do a search on CFC

Lots of good info there

View Postxheartonfire43x, on 5 Apr, 2009 - 05:11 PM, said:

View Postsansclue, on 3 Apr, 2009 - 08:21 AM, said:

Use the "returnVariable" attribute to capture the value.

It is also a good idea to get into the habit of VAR scoping all function local variables. Otherwise, you will run into threading problems if you store the component in a shared scope.


Thanks. Like I said I am just starting with CFC's. I apprenticed under someone who works with ColdFusion 5 so I have been building on what I have learned from him really. Is there any good sites that you know of to learn building and using CFC's?

Was This Post Helpful? 1
  • +
  • -

#5 ComboAlex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 31-July 09

Re: Using CFReturn

Posted 06 August 2009 - 12:41 PM

I also have a small problem with the <cfreturn> tag. Here is my post. I would be very grateful if someone could help me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1