Changes between Version 9 and Version 10 of QuickStart/3:BuildingaForm

Show
Ignore:
Timestamp:
12/31/09 02:11:20 (16 years ago)
Author:
cfgrok (IP: 64.30.223.5)
Comment:

Switched example to use copyToScope(), and removed information on "default" event values

Legend:

Unmodified
Added
Removed
Modified
  • QuickStart/3:BuildingaForm

    v9 v10  
    1111 
    1212{{{ 
    13 <cfset submit = event.linkTo( event.getValue("xe_translate") ) /> 
     13 
     14<cfset event.copyToScope( variables, "xe_translate" ) /> 
     15<cfset submit = event.linkTo( xe_translate ) /> 
    1416 
    1517<cfform action="#submit#"> 
     
    1719    <input type="submit" value="Ok" /> 
    1820</cfform> 
     21 
    1922}}} 
    2023 
     
    2831The event object contains data like a query from a database or (big surprise) the translated version of the phrase that we're asking the user to enter. 
    2932 
    30 To get to one of the variables, you ask the event object to "get its value" with the getValue() function. 
     33To get to the event variables, you can ask the event object to copy them into the scope of your choice, typically the variables scope, with the copyToScope() function. You can also retrieve individual values (variables) from the event object by using the getValue() function, but unless you only need a single value, using copyToScope() will save you a lot of repetitive typing. 
    3134 
    32 There are a few "default" variables added to event object you need to be aware of: 
     35Also note the use of the linkTo() function. This is another convenience method of the event object that will create a link from a supplied event name, so calling event.linkTo( "myevent" ) will produce "index.cfm?event=myevent". If any Model-Glue configuration settings are changed at some point in the future (for example, changing "event" to "e", "index.cfm" to "page.cfm", or enabling SES URLs), the generated links will automatically change to use the new conventions. 
    3336 
    34   * "myself" is the URL of the current page with "?event=" added to it, such as "index.cfm?event=" 
    35   * "self" is the URL of the current page without the "?event=" bit, such as "index.cfm" 
    36   * "event" is the name of the current event. Don't worry about this one. 
    37   * "eventValue" is the name of the URL variable that contains the current event. Don't worry about this one much, either. 
    38  
    39 Therefore, the first line in that frmPhrase.cfm says "make me a link please, and use the value in the event object for 'xe_translate' as the name of the event." 
     37Therefore, the first two lines in that frmPhrase.cfm say "make me a link please, using the value in the event object for 'xe_translate' as the name of the event." 
    4038 
    4139So what's with this "xe_translate" value? "XE" stands for "eXit Event," and has emerged as a best practice in Model-Glue applications (because it's taken from a best practice in Fusebox!). It lets us reuse this view in multiple places because we determine the action page of the form at runtime, instead of hard coding it into our .CFM template. 
    4240 
    43 So where does the value of xe_translate come from? It's time to learn a bit of Model-Glue XML. (Don't worry! I just wrote the entire tag reference, and it's only sixteen tags! And about five of them are just placeholders that contain other tags!) 
     41So where does the value of xe_translate come from? It's time to learn a bit of Model-Glue XML. 
    4442 
    4543To create the actual event handler to display the form, do the following: