-
1. Re: <cfcomponent output="false">
Adam Cameron. Jun 6, 2011 4:32 AM (in response to Owain North)The OUTPUT attribute of the CFCOMPONENT tag suppresses output from the "pseudo-constructor" code: code that is within the CFCOMPONENT tags, but outwith any CFFUNCTION tags. This code is run when the CFC is instantiated.
OUTPUT for CFCOMPONENT loks like it's a boolean, but it's actually tri-state:
OUTPUT=TRUE: behaves as if the whole thing is wrapped in CFOUTPUT tags
OUTPUT=FALSE: behaves as if the whole thign is wrapped in CFSILENT tags
OUTPUT=[not specified] behaves like normal CFML code: will output plain text, but to resolve dynamic values (eg: stuff within hash-marks / pound-signs), one needs to use CFOUTPUT tags.
I guess this is why it's not CFOUTPUT=FALSE by default. If that was the default, then there'd be no way of reflecting that third state.
If I was architecting the CFC implementation, it'd be output=false by default, and if output=true then the code would act like any normal CFML: so like the current [not specified] behaviour. I think the way OUTPUT=TRUE behaves is stupid: who the hell would want ALL their code in CFOUTPUT tags?
Does that answer your question(s)?
--
Adam
-
2. Re: <cfcomponent output="false">
Owain North Jun 6, 2011 4:41 AM (in response to Adam Cameron.)I believe it does, yes. Have a "correct answer", whatever that means for anyone
I'm just working on a new project so I'm trying writing all the cfcs in cfscript purely to see how well it works for me, and having to put in "output=false" statements everywhere just seems just such a waste of time and space.
Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea.
Ta muchly.
-
3. Re: <cfcomponent output="false">
Adam Cameron. Jun 6, 2011 5:15 AM (in response to Owain North)Now... when you say you're doing them in CFScript, do you mean as per CF9's new "script-only CFCs"? You can almost get away with not bothering with OUTPUT=FALSE in that case, as CFScript doesn't generate spurious output like tags do.
The only thing to watch for is if within your script-only CFC you call a non-script CFC method which doesn't have output suppressed: then its spurious output could still bleed out.
--
Adam
-
4. Re: <cfcomponent output="false">
Owain North Jun 6, 2011 5:17 AM (in response to Adam Cameron.)I am indeed going for script-only CFCs, so I guess I could do without. I'm only weary as I've been caught out so many times before by functions adding in the odd space where I don't want it to.
Worth a try I guess...
-
5. Re: <cfcomponent output="false">
Dan Bracuk Jun 6, 2011 5:50 AM (in response to Owain North)Regarding "Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea"
cfc's are one of the ways to produce re-useable code. Sometimes the code you want to re-use involves outputting to a page.
-
6. Re: <cfcomponent output="false">
Owain North Jun 6, 2011 5:53 AM (in response to Dan Bracuk)I'm not saying you'd never want re-usable code that outputs, I'm saying why would you use a cfc for that? Surely you'd use an include file, or a custom tag?
I'd liken a cfc to a class definition in most other languages, and it doesn't feel like the place for outputting to a page to me.
-
7. Re: <cfcomponent output="false">
Adam Cameron. Jun 6, 2011 5:57 AM (in response to Dan Bracuk)Yeah, but if that stuff you want to output is in the pseudo-constructor of the CFC... you're almost certainly going about things the wrong way.
Having spent a good 5sec thinking about it, I cannot think of any situation under which I would consider doing this to be appropriate.
--
Adam
-
8. Re: <cfcomponent output="false">
BKBK Jun 11, 2011 3:41 AM (in response to Dan Bracuk)Dan Bracuk wrote:
Regarding "Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea"
cfc's are one of the ways to produce re-useable code. Sometimes the code you want to re-use involves outputting to a page.
I would never say never to this. Da Vinci and Einstein had to flout convention to find new ways of doing things.
-
9. Re: <cfcomponent output="false">
Owain North Jun 11, 2011 8:50 AM (in response to BKBK)I would never say never to this. Da Vinci and Einstein had to flout convention to find new ways of doing things.
Well last thing I heard Einstein was a .NET guy and Da Vinci was one of those dirty open-source fellas, so for now I'll probably continue with not seeing the point
-
10. Re: <cfcomponent output="false">
BeerIsGood Jul 27, 2011 1:16 PM (in response to Owain North)I believe setting output = 'false" in cfcs also helps prevent memory leaks (and heap dumps). I am not sure if CF9 does this or not as I always add the output = 'false" in the cffunction.
Hope it helps,
Bill

