I got a few Ask a Jedi questions this week that shared one common characteristic - none of them had a "good" answer. Therefore I thought it would be perfect to combine them into one post. If anything, it just goes to show you that ColdFusion provides multiple solutions to a problem, and like many things in life, there isn't one correct answer. Let's start with the first question:
When is it best to have/not have an ending tag with a CFMODULE?
Never. Always. Seriously - it depends. You use a end tag when you want to have "wrapping" logic. HTML is a great example of this. The tag, <B>, tells the browser to begin bolding text. The tag, </B>, tells the browser to stop bolding text. What are some cases where you might need this in custom tags? Layout is one example. I typically wrap my site content with code like so:
<cfmodule template="/siteroot/customtags/layout.cfm" title="Main"> stuff </cfmodule>
This starts a layout (basically includes a header), runs the code inside, and then ends a layout (includes a footer). That's one example, but there are others as well.
Basically the question you want to ask yourself is - does this custom tag have the concept of doing something when starting up and when ending. If not, you do not need a closing tag.
However - there is something to remember. A person may decide to call your custom tag like so:
Notice the fancy self-closing XHTML usage. Cool, eh? Well, what happens then is that your custom tag will actually run twice. This is probably something you don't want to happen, but it is easy to fix. You can either check for the execution mode (this is a variable ColdFusion sets to let you know if the tag is running in "start" or "end" mode, or use cfexit. Here is method one:
<cfif thisTag.executionMode is "start"> do stuff </cfif>
And here is method two:
I definitely prefer method two as it prevents you from needing to wrap your entire custom tag in a CFIF. Just make that line that last line of your custom tag. (By the way, whether you use cf_foo, or cfmodule, the same rules apply.)
Is there an advantage of using either of these built in functions over the other? Fix(), Int(), Round().
Nope. Use the one that makes sense. Seriously - I'm not being flippant. You should use the function that does what you want to do with your numbers.
Tuyen (and what a cool name is that):
In your opinion, what would be the best CF frameworks?
I think I've answered this before. My favorite framework is Model-Glue, but if you ask 10 people you will get 10 different answers. (And readers, please don't post comments 'voting' on frameworks. ;) My suggestion is that you check out all the frameworks and see which one works best for you. You may need to actually build a site to figure this out. I was rebuilding CFLib.org in Mach II and discovered that I really didn't care for it. No offense to Mach II folks, it just didn't work for me. Model-Glue did. But it was a strictly personal feeling, nothing more.