Getting & Setting Values
We all need values in our applications. That is why we interact with the request context in order to place data from our model layer into it so our views can display it, or to retrieve data from a user's request. You will either interact with the event object to get/set values or put/read values directly via the received rc and prc references.
RC/PRC Data Super Highway
We would recommend you use the private request collection (prc) for setting manual data and using the standard request collection (rc) for reading the user's unsafe request variables. This way a clear distinction can be made on what was sent from the user and what was set by your code.
1
//set a value for views to use
2
event.setValue( "name", "Luis" );
3
event.setPrivateValue( "name", "Luis" );
4
5
// retrieve a value the user sent
6
event.getValue( "name" );
7
// retrieve a value the user sent or give me a default value
8
event.getValue( "isChecked", false );
9
10
// retrieve a private value
11
event.getPrivateValue( "name" );
12
// retrieve a private value or give me a default value
13
event.getPrivateValue( "isChecked", false );
14
15
// param a value
16
event.paramValue( "user_id", "" );
17
// param a private value
18
event.paramPrivateValue( "user_id", "" );
19
20
// remove a value
21
event.removeValue( "name" );
22
// remove a private value
23
event.removePrivateValue( "name" );
24
25
//check if value exists
26
if( event.valueExists( "name" ) ){
27
28
}
29
//check if private value exists
30
if( event.privateValueExists( "name" ) ){
31
32
}
33
34
// set a view for rendering
35
event.setView( 'blog/index' );
36
37
// set a layout for rendering
38
event.setLayout( 'main' );
39
40
// set a view and layout
41
event.setView( view="blog/userinfo", layout="ajax" );
Copied!
Important The most important paradigm shift from procedural to an MVC framework is that you NO LONGER will be talking to URL, FORM, REQUEST or any ColdFusion scope from within your handlers, layouts, and views. The request collection already has URL, FORM, and REQUEST scope capabilities, so leverage it.
Copy link
Edit on GitHub