Page Controller 1.0 Documentation: External Variables

Page Controller Information

Blog Entries

Check Out AFF

External Variables

In your model CFCs or your View CFCs you should not break encapsulation. In your page controllers, you should have very limited breaking of encapsulation. It is OK to use external variables so long as they are brought in using the "loadExternalVars" function which should be called from the psuedo-constructor (the area after the first CFCOMPONENT tag and before the first FUNCTION tag).

To load Application.ContactOMatic into variables.ContactOMatic, use the following code:

<cfset loadExternalVars("ContactOMatic")>

Here are the arguments for loadExternalVars:

We could copy Application.ContactOMatic to variables.ContactOMatic and variables.ContactOMatic.Contacts to variables.Contacts using the following code:

<cfset loadExternalVars("ContactOMatic")>
<cfset loadExternalVars("Contacts","ContactOMatic")>

To do the above as well as copy ContactTypes from ContactOMatic, we could do use the following code:

<cfset loadExternalVars("ContactOMatic")>
<cfset loadExternalVars("Contacts,ContactTypes","ContactOMatic")>

If we had an optional component (or variable), we could use skipmissing. So, if you wanted to import Application.NoticeMgr if it exists, we could do the following:

<cfset loadExternalVars(varlist="NoticeMgr",skipmissing=true)>

OR

<cfset loadExternalVars("NoticeMgr","Application",true)>

Although it is acceptable to import shared scope variables using loadExternalVars(), they should not be directly referenced anywhere else in the controller.