Changes between Version 1 and Version 2 of HowTos/HowToUseEventCopyToScope
- Timestamp:
- 12/21/09 21:38:07 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
HowTos/HowToUseEventCopyToScope
v1 v2 8 8 <cfset foot = event.getValue("foot") /> 9 9 <cfset hand = event.getValue("hand") /> 10 <cfset xe .nested = event.getValue("xe.nested") />10 <cfset xe_nested = event.getValue("xe_nested") /> 11 11 }}} 12 12 13 the end result being that each value: foot,hand,xe .nested is now in the variables scope ready for use in your view.13 the end result being that each value: foot,hand,xe_nested is now in the variables scope ready for use in your view. 14 14 15 15 Here in the labs of Model-Glue, we want to reduce developer excise when possible. The new copyToScope() method can be used to short cut the same process. 16 16 17 17 {{{ 18 <cfset event.copyToScope(variables, "foot,hand,xe .nested") />18 <cfset event.copyToScope(variables, "foot,hand,xe_nested") /> 19 19 }}} 20 20 … … 27 27 {{{ 28 28 <cfset defaultArray = ["DefaultForFoot", "DefaultForHand"] /> 29 <cfset event.copyToScope(variables, "foot,hand,xe .nested", defaultArray) />29 <cfset event.copyToScope(variables, "foot,hand,xe_nested", defaultArray) /> 30 30 }}} 31 31 32 Once the function executes, the value of variables.foot is !DefaultForFoot and the value for variables.hand is !DefaultForHand. If no value existed in the event for xe .nested, it will be set to an empty string as per normal when a value is requested from the event that has not been set yet.32 Once the function executes, the value of variables.foot is !DefaultForFoot and the value for variables.hand is !DefaultForHand. If no value existed in the event for xe_nested, it will be set to an empty string as per normal when a value is requested from the event that has not been set yet. 33 33 34 34 Does it only work with the variables scope? 35 35 36 Nope. It will work with any scope you see fit. Session, Server, Application, even a plain ol e struct, though I expect the variables scope will be most often used.36 Nope. It will work with any scope you see fit. Session, Server, Application, even a plain ol' struct, though I expect the variables scope will be most often used.
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)