Ok, I have instantiated an object and all is fine. I am able to call various methods of that object easily, such as myobject.getId(), myObject.getName() , etc etc. These examples all return either a string or numeric value.
Now I have another method that returns a query. I've cfdumped what is returned by the method and it is indeed a query that's being returned.
By when I try to cfloop through the query I get an error.
Here's the cfloop code:
<cfloop query="myObject.myFunction()">
<p><cfoutput&开发者_开发技巧gt;#myObject.myFunction().title#</cfoutput></p>
</cfloop>
The error I get references the very first line and says:
invalid variable declaration [myObject.myFunction()]
Any thoughts? Thanks in advance!
OK, so you just need to change your code slightly so you are doing call to run the query first, e.g.
<cfset qData = myObject.myFunction() />
And then you can loop over it.
<cfloop query="qData">
<p><cfoutput>#qData.title#</cfoutput></p>
</cfloop>
The reason is that the <cfloop/>
tag expects a query object, not a reference to a function.
You could try to see if <cfloop query="#myObject.myFunction()#">
works (with the #'s) but I'm not sure if it will. Besides, each call inside the loop i.e. #myObject.myFunction().title
is going to re-run the query. Not good obviously!
Hope that helps!
精彩评论