Barney B on including a UDF in a CFC

Posted by: scoopseven 17 years, 1 month ago

Having a udf library, you'd naturally want to be able to expose those udfs to your cfcs. Barney Boisvert was nice enough to help me out on this one...
CFC's share an fundementally different variables scope from the calling page, so defining a UDF in the fusebox won't expose it to your CFCs. However, you can certainly include UDFs inside your CFC (in the CFCOMPONENT tag, but not inside a CFFUNCTION tag) and have them accessible. If you have a library of UDFs that you want to have access to in your general page processing and your CFCs, just include them in both places, and you're set. This is called a "mix-in", and it's something that loosely typed languages can really benefit from. However, it's also a good way to make incredibly difficult to debug code, because so much is dynamic. So use them judiciously, and only with good reason. Also, if you're using UDFs in both your model (your CFCs) and your presentation (the fusebox), be careful. Utility functions are 100% ok, but if you've got any business logic in those UDFs, chances are quite good that you have some underlying architectural issues. Which isn't to say that your app won't work, of course, just that maintenance down the road might be more complex than it needs to. Hope that helps. (just saw your second email) You could use a custom tag (via CFIMPORT, of course). Just CFIMPORT it in each template that needs it, including your CFC. That's not a better solution, in my opinion, not to mention calling a UDF is cleaner syntax than using a custom tag for a lot of things. cheers, barneyb

Currently unrated


Recent Tweets

Recent Posts

Archive

2013
2012
2011
2010
2009
2008
2007
2006

Categories

Authors

Feeds

RSS / Atom