如何从一个cfc文件中的函数的查询中调用另一个CFC文件中的函数? [英] How can I call a function in another CFC file from within a query of a function in one cfc file?
本文介绍了如何从一个cfc文件中的函数的查询中调用另一个CFC文件中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有多个函数的cfc文件(info.cfc),如下所示。
I have one cfc file (info.cfc) with multiple functions as shown below.
<cfcomponent output="true" extends="DateFunctions">
<cffunction name="getStatuses" access="remote" returntype="any" output="true" returnformat="plain">
...
</cffunction>
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due
FROM
dbo.tickets
</cfquery>
</cffunction>
</component>
另一个cfc文件(DateFunctions.cfc)包含一个带两个参数的函数,并返回一个日期。
DateFunctions.cfc文件如下:
And the other cfc file (DateFunctions.cfc) containing the a function with two arguments and returning a date. The DateFunctions.cfc file is as follows:
<cfcomponent output="true" name="DateFunctions"">
<cffunction name="addBusinessDays" access="remote" returntype="any" output="true" returnformat="plain">
<cfargument name="daysToAdd"
required="yes"
type="numeric"
hint="The number of whole business days to add or subtract from the given date">
<cfargument name="date"
required="No"
type="date"
hint="The date object to start counting from.."
default="#NowDateTime#">
...
... <!--- Perform some tasks --->
<cfreturn Date>
</cffunction>
</cfcomponent>
问题:
我以为我可能可以做类似的工作:
I thought I might have been able to do something like:
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due,
(
<cfinvoke component="DateFunctions" method="addBusinessDays" returnVariable="Date">
<cfinvokeargument name="daysToAdd" value="#dbo.tickets.Days_Due#">
<cfinvokeargument name="date" value="#dbo.tickets.Start_Date#">
</cfinvoke>
) AS Due_DATE
FROM
dbo.tickets
</cfquery>
</cffunction>
推荐答案
您可以执行以下注意事项是循环的附加处理。
You could do the following with the caveat of there would be additional processing for the loop.
编辑:根据以下讨论,将cfuput更新为cfloop
Per discussion below, updated cfoutput to cfloop
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due,
'' as Due_DATE
FROM
dbo.tickets
</cfquery>
<cfset df = createobject("component","DateFunctions")>
<cfloop query="records">
<cfset records.Due_DATE = df.addBusinessDays(Days_Due, Start_Date)>
</cfloop>
<cfreturn records>
</cffunction>
这篇关于如何从一个cfc文件中的函数的查询中调用另一个CFC文件中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文