Jump to content

Using Cfcomponent

Recommended Posts

I'm working on a cfcomponent application. I currently have 2 functions in my cfcomponent. My first function is getData which queries the DB and takes 2 arguments. My second function is buildTable which builds a table out of the query from getData. The problem I have is I get the error "Variable MYTABLE is undefined". myTable is created in my buildTable function.

<cfinvoke component="emissions" method="getData" returnvariable="myTable"><cfinvokeargument name="year" value="2007" /><cfinvokeargument name="location" value="BC" /></cfinvoke><cfdump var="#myTable#" />

EDIT:I got the problem resolved! Instead of my getData function calling buildTable I have buildTable calling getData and that seems to work :)

Edited by vchris
Link to post
Share on other sites
  • 2 weeks later...

I see you resovled this, but I was working with a couple CFCs today and figured I might offer this little tip.When I make calls to functions or components I build all my code around them returning a pass or fail message. And data structure(s) that are built inside the component are defined in the request scope. Since a component can only return one variable, I ran into situations where an SP I was calling inside the CFC had multiple record sets and it was odd to pass one in the return variable and then force the other somewhere else (request scope). So now, I wrap almost everything I do in the CFC with a cftry/cfcatch and have the return variable pass back a pass or fail string. If it is fail, i don't even bother looking in the request scope for anything, if it passes, then I do. I now do that with all my components so my code is consistent.Does that make any sense?

Link to post
Share on other sites

I wish I could give a comparison but I don't know PHP enough to do so.:-(All I can really say is that CFCs rock.:)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...