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

my fisrt cfc

Participant ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

I tried to learn to use cf component by creating a simple cfc.
All I want to do within the cfc is to provide 1 query so within the application this query doesn't have to be created many times.

I created a getFrmTypes.cfc this way:
<!--- getFrmTypes.cfc --->
<CFCOMPONENT>
<CFFUNCTION Name="FrmTypes" ReturnType="query">
<cfquery name="getTypes" datasource="MyDB">
Select * from TblForms order by FormID Asc
</cfquery>
</CFFUNCTION>
</CFCOMPONENT>

Then on the CF template that is calling this cfc I wrote:
<CFINVOKE Component="getFrmTypes" Method="FrmTypes" ReturnVariable="FormTypesQuery">

When I run this template I got this error:
The value returned from function FrmTypes() is not of type query.
If the component name is specified as a return type, the reason for this error might be that a definition file for such component cannot be found or is not accessible.
line 12

12 : <CFINVOKE Component="getFrmTypes" Method="FrmTypes" ReturnVariable="FormTypesQuery">
13 :
14 : <table border="0">

I don't understand what is the meanng of this error and how can I make correction, please help.

TOPICS
Getting started

Views

737

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 ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

Your function doesn't return anything. I don't see a cfreturn tag anywhere.

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
Engaged ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

As Dan stated, CFfuntions need to have a cfreturn:

<CFCOMPONENT>
<CFFUNCTION Name="FrmTypes" ReturnType="query">
<cfquery name="getTypes" datasource="MyDB">
Select * from TblForms order by FormID Asc
</cfquery>
<cfreturn getTypes> <-- added ---
</CFFUNCTION>
</CFCOMPONENT>


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
Participant ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

I got it!! thank you for pointing that out ! Whew!

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 ,
Nov 07, 2006 Nov 07, 2006

Copy link to clipboard

Copied

I added: <CFRETURN FrmTypes> and run the app. again, still get the same
error.

In your example you don't want to return the function, you want to
return the query you generated in the function.

<cfreturn getTypes>


That will remove the error you are receiving but the function will not
be doing what you want. The way it is written it will still run the
query every time the function is called to get the data. To do what you
stated, not have the query created many times, you are going to want to
have one function (or in the component pseudo constructor) create the
query and store it, then another function to read it back to any code
that needs to use it. You will then need to store the initiated
component in some type of persistent variable so that the query is
persisted and does not get re-run unnecessarily.

<CFCOMPONENT>
<CFFUNCTION Name="set_FrmTypes" ReturnType="void">
<cfset var getTypes = ""> <!--- The var keyword initilizes the
getTyes variable to be local to this function to prevent problems. --->

<cfquery name="getTypes" datasource="MyDB">
Select * from TblForms order by FormID Asc
</cfquery>

<cfset variables.types = getTypes> <!--- This sets the query to an
internal variable of the component/object--->
</CFFUNCTION>

<cffunction name="get_frmTypes" returnType="query">
<cfreturn variables.types> <!--- This returns the query from the
internal variable--->
</cffunction>
</CFCOMPONENT>


Then in your calling code.
<!--- This invokes the component calling the set_frmTypes function to
initilize the query and stores the result in the application scope so it
can be used anywhere in the given application --->
<CFINVOKE Component="getFrmTypes" Method="set_FrmTypes"
ReturnVariable="application.FormTypesQuery">

<!--- The calls the above saved component and gets the query out of it. --->
<CFINVOKE Component="#application.FromTypesQuery#" Method="get_frmTypes"
ReturnVariable="theQuery">





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
New Here ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

LATEST

why my code is still not working?

can you help me please

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