Var Keyword in Views

0 views
Skip to first unread message

Brian H.

unread,
Dec 12, 2009, 3:22:27 AM12/12/09
to Mach-II for CFML
Hey Folks.

I've been using the local (var) scope in all of my components, but not
in my views as I've always associated CFMs with single-theaded
execution, but it just occurred to me that the view CFM files are
cfincluded by persistent objects (the M2 framework) and probably
require var scoping too!

If so, then I am a dummy and I have to revisit some of my sites. Can
anyone confirm that we indeed need to var scope all of our variables
inside of our views?

Thanks!

-Brian

sipa...@gmail.com

unread,
Dec 12, 2009, 9:23:48 AM12/12/09
to mach-ii-for...@googlegroups.com
Brian,

You do not need to var scope variables in your views.

You are right to consider this important question and it shows you understand the importance of var scoping properly.

MachII includes the views on a per request basis in such a way as not to require var scoping, so no worries.


DW
--
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to mach-ii-for...@googlegroups.com
To unsubscribe from this group, send email to mach-ii-for-coldf...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets: http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/

Sent from my Verizon Wireless BlackBerry

Matthew

unread,
Dec 13, 2009, 4:38:05 PM12/13/09
to Mach-II for CFML
Hi Brian

I'm pretty sure that there is no need to var scope because everything
in your view is treated as Request scope. You are right that M2
includes the view from within a component however the component is a
Singleton in the Application scope, so each thread has it's own
instance therefore everything is in the Request scope.

Cheers
Matthew

Brian H.

unread,
Dec 14, 2009, 1:53:48 PM12/14/09
to Mach-II for CFML
DW, ok thank you!

Matthew, but saying that the M2 components are singletons in the
Application scope is further evidence that everything -in- those
components should very much be var scoped, and I think that the
statement "so each thread has it's own
instance" is false because these are singletons.

I appreciate the input guys, though I am no 100% convinced. I guess a
simple test case would prove once and for all.

Here is what I did.

<cfset MACHII_CONFIG_MODE = -1 />

In my view, I have

<cfset myvar = RandRange(1,100)>
<cfset sleep(5000)>
#myvar#

I started one page thread, as it was running (sleeping) I started the
other. If var scoping would have been required, then I think that the
final outputted values should have been identical on both requests
(race condition) but in fact, the values were different.

So, it looks like you guys are correct, and var scoping is NOT
required in your views. Thanks! Helps me sleep a bit better.

-Brian

Peter J. Farrell

unread,
Dec 14, 2009, 2:08:49 PM12/14/09
to mach-ii-for...@googlegroups.com
The ViewContext in which all views are rendered inside of is created for each request and stashed in the *request* scope.  No need to worry about var scoping.

.pjf

Brian H. said the following on 12/14/2009 12:53 PM:
--

The Harmonious Programmer

Peter J. Farrell
Email: pe...@mach-ii.com | pjf@maestropublishing
Blog: The Harmonious Programmer
Twitter/Identi.ca: @maestrofjp

Brian H.

unread,
Dec 14, 2009, 2:50:39 PM12/14/09
to Mach-II for CFML
Very cool.

Thanks for the input guys!

-Brian
> The Harmonious Programmer
> <http://feeds.feedburner.com/%7Er/TheHarmoniousProgrammer/%7E6/1>
>
> *Peter J. Farrell*
> Email: pe...@mach-ii.com | pjf@maestropublishing
> Blog: The Harmonious Programmer <http://blog.maestropublishing.com>
> Twitter/Identi.ca: @maestrofjp
>
>  TheHarmoniousProgrammer.1.gif
> 64KViewDownload
Reply all
Reply to author
Forward
0 new messages