In my last Zeus preview, I discussed what I thought was a minor, but nice, language enhancement. Turns out the "minor" feature got quite a few replies from my readers. So in that vein, I'm posting another "minor but good" improvement this week. In current versions of ColdFusion, you have two ways to set cookies:
<cfcookie name="chocolate" expires="10" value="yum">
<cfset cookie.saints = "StopBeingOverConfident">
The tag version of cfcookie allows you to set a cookie name and value as well as a set of attributes that control how long the cookie persists and how it is accessed. The script version (or the 'simple cfset' version) only allows you to set a name and value. ColdFusion sets this cookies as a session cookie which means it will go away as soon as you close your browser window.
ColdFusion Zeus fixes this in a rather simple, and elegant way. You can still set cookies exactly the same way you do now. But if you want to specify specific attributes of the cookie, you can use a structure instead:
<cfscript>
cookie.age = {value="38", expires="never"};
</cfscript>
You can specify any valid value for the cfcookie tag as a name/value pair in the structure.
So nothing earth shattering, but it's one more thing you can now do in cfscript versus tags.
Archived Comments
And, in case it isn't obvious to people that hate using the cfscript tag for one line of code, you can set via: <cfset cookie.age = {value="38", expires="never"}>
But why would you do that? That's more typing than just the tag. I think it's pretty implied that the blocks above would be in templates with more code.
You'd be surprised at the amount of:
<cfscript>
one line of code;
</cfscript>
I see at work and in open source projects. I bitch about this all the time. :)
I agree with Todd on this one.. when I only have to set one variable, <cfset> it is for me.
I always depends on the context I guess...
I definitely agree - but again - this is not really the point here. Right guys? :)
i use <cfscript>one line of code;</cfscript> all the time and i don't see a problem with that. It's just a personal preference and i don't understand why people pick about it. besides when you need to add more lines, it makes that easier rather than changing from cfset to cfscript.
I agree with Todd that it makes sense if that is the only line in your script tags, or if you are not using script syntax in your code yet.
Heh, so, is _no_ one going to comment on the feature? You guys drive me crazy sometimes. But then again - I appreciate the surprising way folks react sometimes! :)
Age expires never - you've invented immortality!? :D
Hmm. I'll probably stick with cfcookie because of attribute hinting in Dreamweaver and it's daft to switch over to cfscript just for 1 or 2 lines if it's not necessary.
Would the next release of Dreamweaver or even CFBuilder support attribute hinting inside parentheses, I wonder?
Yay for your blog entry, Ray! :-) From us crazies.
CFB kinda does it now for ormsettings within App.cfc.
Actually the more I use CFSCRIPT the more I like it.
Agreed for one off or code "ready" ness for only one or two settings but for lengthy assignments it is more elegant and faster.
I am actually happy about the addition of this to cfscript. I write almost exclusively in script these days and any time I can remove a section of code from my "nonScriptFunctions.cfc" is a good day for me.
For me it looks a bit weird.
The struct notation is used here not only to set values but for functionality behind. I'd definitly prefer a cookie() function.