0

Event Args and Variables scope

ColdFusion
Some action on the mailing lists (and discussion in the office with Dave) brought up a good point about separating Mach-II event variables from your view/model/etc.  One might want to move their app to a different framework some day, and if you had event.getArg() all through your view, it could make it inconvenient to switch over. 

Doing something like this would help separate mach-II from your app's views.

<cfset structAppend(variables,event.getArgs())/>

              

This copies all of your Event args into your variables scope so you could access them via the usual "variables.event"  or "variables.targetevent"  and so on.
tags:
ColdFusion
Sami Hoda said:
 
Very useful.
 
posted 1276 days ago
Add Comment Reply to: this comment OR this thread
 
Peter J. Farrell said:
 
Aaron, although this point has no impact -- thought you should be aware of it. Remember that your views are rendered inside of the Mach-II ViewContext cfc. So when you do put your event arguments in the variables scopes - they are going in the ViewContext's internal CFC variables scope and they will be available to all views during the lifetime of the request. The ViewContext is created once per request so there shouldn't be any threading problems. However, for instance, in one view you put something in the variables scope and you forget to do it in another view -- the data available in the variables scope is old (from the first view). This may cause a strange bug, but it is expected behavior for ColdFusion.
 
posted 1272 days ago
Add Comment Reply to: this comment OR this thread
 
 
Thanks for the info Peter. I'm sure the point does have some impact. I will have to watch for that behavior as I get deeper into this project.
 
posted 1271 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Fuelly