Created
September 16, 2014 22:09
-
-
Save ryanguill/631518c2ea445cf2f2b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This CFC is intended to be used with fw/1 and stored in the session scope. | |
| session.flash = beanFactory.getBean("FlashStorage"); //if you are using fw/1 | |
| or | |
| session.flash = FlashStorage(); | |
| it is inteneded to be used to store any variables you would like to hold on | |
| between requests, and then populate those variables back out into your rc, | |
| but you could use this with any structure or scope. | |
| */ | |
| component { | |
| public any function init () { | |
| variables.instance = {}; | |
| } | |
| /* | |
| set(key, value) | |
| use this method to set a variable into the flash storage directly | |
| but most of the time you will likely use the store method | |
| */ | |
| public void function set (required string key, required any value) { | |
| variables.instance[key] = value; | |
| } | |
| /* | |
| store(rc, key) | |
| use this method to take a variable out of your rc, whatever its current value is, and store | |
| it in the flash storage to be restored later. You can also optionally provide a defautl value | |
| in case the key does not currently exist in the rc. | |
| session.flash.store(rc, "user"); //store whatever is currently in rc.user | |
| session.flash.store(rc, "errorMessage", ""); //if errorMessage exists in rc, store it, otherwise set it to "" | |
| */ | |
| public void function store(required struct rc, required string key, any defaultValue = "") { | |
| if (structKeyExists(rc,key)) { | |
| set(key,rc[key]); | |
| } else { | |
| set(key,defaultValue); | |
| } | |
| } | |
| /* | |
| get() | |
| get the stored structure and clear the stored data - you probably want to use the restore(rc) method | |
| */ | |
| public struct function get () { | |
| local.out = duplicate(variables.instance); | |
| structClear(variables.instance); | |
| return local.out; | |
| } | |
| /* | |
| restore(rc) | |
| pass in the structure you want to populate the stored variables back into. | |
| */ | |
| public void function restore (required struct rc) { | |
| structAppend(arguments.rc, get()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment