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

How can I acheive this technique with CFC's?

Engaged ,
Apr 01, 2008 Apr 01, 2008
Hi,

I'm building a CMS type thing, and for my templates I'll need access to some functions that do certain things so I can output the various data I need. At the moment, I have separate methods in a component that do individual things - they do not work together in any way. However, what I thought would be nice, is to find a way where I can use these CFC's together.

e.g. If I had a method that got user details based on an ID passed as an argument, I would like to have a way that perhaps gets there billing details if I want...or whatever is in there basket etc. The normal way I would do this is to write many completely different methods for a specific purpose.

Is there a way to do something like:

#getUserDetails("3434").getOrderHistory().getProduct("78")#

By that kind of syntax (which is probably completely wrong), I'd like to say:

Get the user details with an ID I pass to the getUserDetails method, then with this, get the order history via a CFC called getOrderHistory (which would use the ID in getUserDetails and then when I have this, get a specific product from the getOrderHistory based on another ID of the product. This would all then probably return some kind of structure or array that I can loop and do with what I like.

Is this kind of functionality possible in Coldfusion? I don't even know what I'd call this method / technique.

I want to become a better Coldfusion user - so any advice would be very welcome.

Thanks,
Mikey.
535
Translate
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 ,
Apr 01, 2008 Apr 01, 2008
Write a get everything method that calls all the other functions.
Translate
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 ,
Apr 01, 2008 Apr 01, 2008
Hi Dan,

Thanks for the reply! Any chance I could be cheeky and ask for some kind of example? I'm really stumped with this because I'm not even sure what the techniques called, thus searching for stuff on this is hard. Is it called inheritance? Or have I got that wrong entirely? Hmm.

Is it even a good way to go about things in the first place?

Thanks for your help!
Mikey.
Translate
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 ,
Apr 01, 2008 Apr 01, 2008
I'm not smart enough to do things with inheritence so my approach for a get everything function would be something like this.

cffunction returntype = structure
cfargument
var TheStructure = StructNew()

cfinvoke returnvariable = TheStructure.something argumentcollection=arguments

more of these

cfreturn TheStructure
Translate
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 ,
Apr 01, 2008 Apr 01, 2008
Kap,

Although I cannot give you any insight as in how this can be done, I believe the concept of what your looking for can be done. I know if Fusebox, I can reference some useful variables via #myFusebox.getCurrentCircuit().getAlias()# and such.

Once again, even though I cannot tell you exactly how you can do this, I think that the example you gave would have to be 2 parts. From what you wrote I think you are trying to find a list of orders for one user that all include a specific item. #getUserDetails(userID).getOrderHistory# would work to return a list of orders for a user, but from there I would think you wound have to build something else to search for the orders containing that item.

Now if you wanted to do it all at once, I would suggest maybe making a method such as #getUserDetails(userID).getOrdersByItem(itemID)# that would return a list of orders containing a specific item...

I could be way off from what you are looking for and everything I have typed here may be useless for you, but I just thought I would offer my opinion. Let me know if you have any questions.
Translate
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 ,
Apr 01, 2008 Apr 01, 2008
LATEST
Kap,

Although I cannot give you any insight as in how this can be done, I believe the concept of what your looking for can be done. I know if Fusebox, I can reference some useful variables via #myFusebox.getCurrentCircuit().getAlias()# and such.

Once again, even though I cannot tell you exactly how you can do this, I think that the example you gave would have to be 2 parts. From what you wrote I think you are trying to find a list of orders for one user that all include a specific item. #getUserDetails(userID).getOrderHistory# would work to return a list of orders for a user, but from there I would think you wound have to build something else to search for the orders containing that item.

Now if you wanted to do it all at once, I would suggest maybe making a method such as #getUserDetails(userID).getOrdersByItem(itemID)# that would return a list of orders containing a specific item...

I could be way off from what you are looking for and everything I have typed here may be useless for you, but I just thought I would offer my opinion. Let me know if you have any questions.
Translate
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