views:

41

answers:

1

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>#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!

+6  A: 

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!

Ciaran Archer
That did it, thanks! I could have sworn I had tried putting the method call into a variable and then looping over the variable, but I guess I hadn't.
Gary